Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: if/else command


From   "Anek Stata" <[email protected]>
To   [email protected]
Subject   st: if/else command
Date   Thu, 06 Jan 2005 14:54:16 +0000

Greetings everyone,

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.

Thanks a lot,
Ane

_________________________________________________________________
Powerful Parental Controls Let your child discover the best the Internet has to offer. http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines Start enjoying all the benefits of MSN� Premium right now and get the first two months FREE*.

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index