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

RE: st: STATA Vs. SAS


From   Fred Wolfe <fwolfe@arthritis-research.org>
To   statalist@hsphsun2.harvard.edu
Subject   RE: st: STATA Vs. SAS
Date   Wed, 27 Nov 2002 15:05:24 -0600

Yes, that's what I meant.  In my simple example, using the Stata
alternative isn't such a problem, but often I want to apply a subcondition
to only some values.  So, e.g.,

if x=0 then y=1;
else if 1 < x < 10 then do;
  <other sas commands>;
end;
else if 11 < x < 20 then do;
  <other sas commands>;
end;


It's difficult and tedious to have to write the multiple levels of
conditions if the program is going to evaluate every if statement.
In general, this type of code often works very well:

gen y = 1 if x == 0
some command if inrange(x,2,9)
... more .. if needed
some command if inrange(x,12,19)
... more .. if needed

Practically, if the if condition is complicated one often makes a new variable or local macro, as in

gen newvar = cond(x == 1 & age >27 & date >mdy(01,01,2002),1,0)

then just using - if newvar- for the if condition.



Fred Wolfe





---------------------------------------------------------------------------- ------------------------
Fred Wolfe Tel (316) 263-2125
National Data Bank for Rheumatic Diseases Fax (316) 263-0761
Wichita, Kansas fwolfe@arthritis-research.org
---------------------------------------------------------------------------- -------------------------

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