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

st: RE: dummy creation


From   "Steichen, Thomas J." <[email protected]>
To   <[email protected]>
Subject   st: RE: dummy creation
Date   Thu, 6 Oct 2005 08:17:13 -0400

Dirk Nachbar writes:
 
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 
} 

---------------------------

The problem is that -if- does not operate value by value.  
Rather it assumes -sex- is shorthand for -sex[1]-, that is, 
the value of the first observation (in current sort order) of sex.

You must use 

  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 

Or, you can consider using the -cond()- function (See Nick Cox's article in the recent Stata Journal)


-----------------------------------------
CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s),
contains information that may be confidential, protected by the
attorney-client or other legal privileges, and/or proprietary non-
public information. If you are not an intended recipient of this
message or an authorized assistant to an intended recipient, please
notify the sender by replying to this message and then delete it from
your system. Use, dissemination, distribution, or reproduction of this
message and/or any of its attachments (if any) by unintended recipients
is not authorized and may be unlawful.


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