Hi, I'm new to Stata, and have two questions on generating variables. 1. I'm using the Census data would like to generate a variable TOEFL (an English test), and then correspond the average score of countries for which scores are available to those who identify themselves from a particular country of origin.
gen toefl=233 if filipino==1 replace toefl=224 if malaysian==1 replace toefl=211 if chinese==1 replace toefl=207 if indonesian==1 replace toefl=207 if vietnamese==1 replace toefl=202 if korean==1 replace toefl=201 if laotian==1 replace toefl=199 if cambodian==199 replace toefl=194 if thai==1 replace toefl=193 if taiwanese==1 replace toefl=183 if japanese==1 gen mtoefl=1 if toefl==0 I'd like to generate mtoefl for missing toefl scores since I don't have data on some of the countries. Is my last statemetn correct? But Stata has generated x missing values, for which x is my sample size! A look in the data browser shows that a) the those with missing toefl has a "-" in the field, rather than 0. so is the statement invalid? and b) all observations show "-" in the field of mtoefl. so obviously I didn't succeed in creating a dummy variable for missing variables. 2. Stata executes it and tells me "end of file," but only the first variable is generated, none of the rest shows up in the variables list. If I take away the /* on before generating easteuropesoviet=0, then Stata says invalid "ancfrst1" which is a valid variable from the census again! Thanks so much for help. Alice gen wcneuropean=0 replace wcneuropean=1 if ancfrst1==001-099 & ancscnd1==001-099 & ancfrst1==181 & ancscnd1==181 /* */ ancfrst1==183 & ancscnd1==183 & ancfrst1==185 & ancscnd1==185 & /* */ ancfrst1==187 & ancscnd1==187 & /* */ ancfrst1 !=100-180 & anscnd1 !=100-180 & /* */ ancfrst1 !=182 & ancscnd1 !=182 & /* */ ancfrst1 !=184 & ancscnd1 !=184 & /* */ ancfrst1 !=186 & ancscnd1 !=186 & /* */ ancfrst1 !=188-999 & ancsnd1 !=188-999 /* --> Right here! gen easteuropesoviet=0 replace easteuropesoviet=1 if ancfrst1==100-180 & ancfrst1==190 & ancfrst1==191 & ancfrst1==193 /* */ & ancscnd1==100-180 & ancscnd1==190 & ancscnd1==191 & ancscnd1==193 & /* */ ancfrst1 !=001-099 & ancscnd1 !=001-099 & /* */ ancfrst1 !=181-189 & ancfrst1!=192 & ancfrst1 !=194-999 & /* */ ancscnd1 !=181-189 & ancscnd1!=192 & ancscnd1 !=194-999 /* . . ================================================================= Instructions for joining and leaving this list, remarks about the problem of INAPPROPRIATE MESSAGES, and archives are available at: . http://jse.stat.ncsu.edu/ . =================================================================
