Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Joe Canner <jcanner1@jhmi.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: Cannot generate a dummy variable using if command |
Date | Fri, 2 Aug 2013 18:21:57 +0000 |
To elaborate a bit on what Sergiy said... The reason you need to add "!missing(age)" (or similar) to your statement is that a missing value is the largest value there is (i.e., the highest number possible for that data type, plus one). Thus, a missing value for age will always satisfy the condition "if age>25" This is in contrast to SAS, for example, where missing values are the lowest value there is (i.e., the lowest number possible minus one). Regards, Joe -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Sergiy Radyakin Sent: Friday, August 02, 2013 2:14 PM To: statalist@hsphsun2.harvard.edu Subject: Re: st: Cannot generate a dummy variable using if command There is nothing wrong. Type summarize age and look at the min age reported. A simpler and more robust version is something like: gen old=age>25 if !missing(age) Finally note that in nlsw88 dataset (if you are using it) there are no individuals younger than 34. Best, Sergiy On Fri, Aug 2, 2013 at 2:05 PM, Joseph Kwan <JXK180@bham.ac.uk> wrote: > I would like to generate a variable for people older than 25 years > old, > > so I use > > gen old=1 if age>25 > > but then Stata returns with an old dummy variable with all 1 for all observations. > > I checked the syntax and I do not know what is wrong. > > Is Stata known to have faults like that? > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/