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

st: RE: dummy creation


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: dummy creation
Date   Thu, 6 Oct 2005 13:24:20 +0100

You are confusing the -if- command and the -if- qualifier
which are quite different constructs. See 

FAQ     . . . . . . . . . . . . . . . . . . . . .  if command vs. if qualifier
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  J. Wernow
        6/00    I have an if command in my program that only seems
                to evaluate the first observation, what's going on?
                http://www.stata.com/support/faqs/lang/ifqualifier.html

Note that 

. search if 

would have pointed to this. Note also that 

early = 1 

is illegal in Stata. In your code you need -replace-. As whether -sex- is 1 or 2 
appears irrelevant to your dummy, then unless you are dealing with three or more 
sexes, code to do what you want you appear to be

gen early = (anypen1==1 | anypen2==1 | anypen3==1 | anypen4==1 | anypen5==1) & age < 60

Do please find out how not to send HTML in your mailer. A document referred to 
in the Statalist FAQ leads to advice on this point. 

Nick
n.j.cox@durham.ac.uk 

Dirk Nachbar

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 
} 

*
*   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