I am using Stata 8.1 on Win2000. My data set contains variable
"certification", which takes values 1 or 2 only. I am trying to group
respondents from these two "certification" sets into age groups. For SOME
REASON, the if command for certification==1 executes all the replace
commands, but when it goes to the second if, none of the replace commands
within the curly brackets get executed.
Below is the code I am using:
----------------------------------------
if certification == 1 { ;
replace age = 22 if age <= 5;
replace age = 30 if age >= 6 & age <= 15;
replace age = 40 if age >= 16 & age <= 20;
replace age = 50 if age > 20;
{ ;
else if certification == 2 { ;
replace age = 22 if age <= 3;
replace age = 30 if age >= 4 & age <= 13;
replace age = 40 if age >= 14 & age <= 24;
replace age = 50 if age == 25;
replace age = 50 if age == 26;
replace age = 50 if age == 27;
replace age = 50 if age == 28;
};
----------------
I have tried to break it on purpose, writing "if certification==3". This
gives me NO ERRORS, even though there is never a value 3 in variable
certification. This is obviously wrong. I have also tried the code with and
without "else" (just trying to execute another if), to no avail. I've tried:
...
replace age = 50 if age > 20;
};
else{;
replace age = 22 if age <= 3;
...
and
...
replace age = 50 if age > 20;
};
if certification==2{;
replace age = 22 if age <= 3;
...
Since the help file is USELESS, I'd like to ask for your help, if you can
spot what I am doing wrong.