[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Sayer, Bryan" <BSayer@s-3.com> |

To |
"'Nick Cox '" <n.j.cox@durham.ac.uk>, "'statalist@hsphsun2.harvard.edu '" <statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: STATA equivalent to SAS subsetting "else if" statements? |

Date |
Tue, 8 Jul 2003 17:49:42 -0400 |

.N is a special missing, to distinguish NIU, from don't know, refused, invalid, etc. The complete set of letters, plus '.' and '._' are available in SAS. Stata has a similar set, but the most important thing to remember is that in SAS missings are the SMALLEST value and in Stata they are the LARGEST value. Also, SAS is not case sensitive (in general) while Stata is. Bryan Sayer Statistician, SSS Inc. -----Original Message----- From: Nick Cox To: statalist@hsphsun2.harvard.edu Sent: 7/8/03 3:18 PM Subject: st: RE: STATA equivalent to SAS subsetting "else if" statements? Deborah Garvey > I have generally used SAS for data manipulation, so I am > not familiar with the best way to code the equivalent of > the subsetting "else if" statement in STATA. > > This SAS code defines RACEETH hierarchically, based on the > value of HISPANG and RACEG. It only permits RACEETH to > change once (from default missing to a valid value), at the > first occurrence of a true IF statement: > > if hispang = 0 then do; > if raceg = 1 then raceeth = 1; > else if raceg = 2 then raceeth = 2; > else raceeth = 3; > end; > else if hispang = 9 then raceeth = .N; > else if hispang ge 1 and hispang < 9 then raceeth = 7; > > How do I accomplish this in STATA? In Stata (cf. http://www.stata.com/support/faqs/res/statalist.html#spell) you have to flip everything round to go on the right-hand side. Also == tests for equality; = assigns RHS to LHS only. This looks like gen raceeth = . replace raceeth = 1 if hispang == 0 & raceg == 1 replace raceeth = 2 if hispang == 0 & raceg == 2 replace raceeth = 3 if hispang == 0 & raceeth == . replace raceeth = <whatever> if hispang == 9 replace raceeth = 7 if hispang >= 1 & hispang < 9 Or we could start with gen raceeth = 1 if hispang == 0 & raceg == 1 replace raceeth = 2 if hispang == 0 & raceg == 2 replace raceeth = 3 if hispang == 0 & raceeth == . replace raceeth = <whatever> if hispang == 9 replace raceeth = 7 if hispang >= 1 & hispang < 9 Somebody else please say what .N is in SAS as I have .Not a clue. Nick n.j.cox@durham.ac.uk * * 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/ * * 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/

- Prev by Date:
**st: STATA training in SF Bay Area** - Next by Date:
**Re: st: oprobit standardized coefficients** - Previous by thread:
**st: STATA training in SF Bay Area** - Next by thread:
**st: BSQREG and WEIGHTS** - Index(es):

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