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

Re: st: dummy creation


From   Ulrich Kohler <kohler@wz-berlin.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: dummy creation
Date   Thu, 6 Oct 2005 14:23:58 +0200

Dirk Nachbar wrote:
> I have a syntax question and help would be appreciated. I want to generate
> a dummy if certain conditions apply, but it does not seem to work as the
> early dummy is always 0.
>
> -----------------
> gen early=0
> if sex==1 & (anypen1==1 | anypen2==1 | anypen3==1 | anypen4==1 |
> anypen5==1) & age < 65 {
> early=1
> }
> if sex==2 & (anypen1==1 | anypen2==1 | anypen3==1 | anypen4==1 |
> anypen5==1) & age < 60 {
> early=1
> }

Dirk,

you seem to confuse the command -if- with the -if- qualifier. I propose:

gen early = 0
replace early = 1 if sex==1 ///
     & (anypen1==1 | anypen2==1 | anypen3==1 | anypen4==1 | anypen5==1)  ///
     & age < 65
replace early = 1 if sex==2 ///
     & (anypen1==1 | anypen2==1 | anypen3==1 | anypen4==1 | anypen5==1)  ///
     & age < 60


For more information on the if-qualifier see -help if-, for more information 
on the if-command see -help ifcmd-. Note that the if-command is a programming 
command. Usually it is not what Stata newcomers looking for, and in 
especially it is not the same as the "if" in SPSS. Hence, SPSS is not Stata, 
and the Stata proof for this is:

. di cond("SPSS"=="Stata","yes","no")
no

Many regards
Uli        

-- 
kohler@wz-berlin.de
+49 (030) 25491-361
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index