Statalist The Stata Listserver


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

st: RE: Another spss do if-translation-problem


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Another spss do if-translation-problem
Date   Tue, 31 Oct 2006 11:04:23 -0000

I don't know SPSS, but it certainly looks long-winded here.  

More importantly, my guess is that you have translated
the code appropriately -- assume that each do-if in SPSS 
is executed in turn -- so what remains mysterious is what 
you mean by "did not work". 

-if ... else ...- is certainly _not_ the answer for 
reasons explained at 

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

Incidentally, check out -cond()-. 

replace hrolle = cond(hrolle < 200, hrolle - 100, hrolle - 200) 
replace hrolle = cond(hrolle < 20,  hrolle - 10, cond(hrolle < 30, hrolle - 20, hrolle - 30)) 

There is a tutorial at 

SJ-5-3  pr0016  . . Depending on conditions: a tutorial on the cond() function
        . . . . . . . . . . . . . . . . . . . . . . .  D. Kantor and N. J. Cox
        Q3/05   SJ 5(3):413--420                                 (no commands)
        tutorial on the cond() function

and FAQs with examples at 

http://www.stata.com/support/faqs/data/condition.html

http://www.stata.com/support/faqs/data/leapyear.html

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

Schneider Julia
 
> > Could anybody advise me how to translate the following do 
> if-condition from SPSS to STATA? I tried to use replace (but 
> it did not work the way I tried to). Could I use if> ...>  
> else if> ...>  else?

> > Here is the original spss-syntax:
> > 
> > 				compute hrolle=caseid/100000.
> > 				exec.
> > 
> > 
> > 				do if hrolle<200.
> > 				compute hrolle=hrolle-100.
> > 				else.
> > 				compute hrolle=hrolle-200.
> > 				end if.
> > 				exec.
> > 
> > 				do if hrolle<20.
> > 				compute hrolle=hrolle-10.
> > 				else if hrolle < 30.
> > 				compute hrolle=hrolle-20.
> > 				else.
> > 				compute hrolle=hrolle-30.
> > 				end if.
> > 				exec.
> > 
> > 				compute rolle=trunc(hrolle).
> > 				exec.
> > 
> > 				formats rolle (F1).
> > 				Exec.
> > 
> > 				And the failed version in stata 
> with replace:
> > 
> > 	***
> > 
> > 	gen hrolle=caseid/100000
> > 	replace hrolle=hrolle-100 if hrolle<200
> > 	replace hrolle=hrolle-200 if hrolle>=200
> > 	replace hrolle=hrolle-10 if hrolle<20
> > 	replace hrolle=hrolle-20 if hrolle<30
> > 	replace hrolle=hrolle-30 if hrolle>=30
> > 
> > 	gen rolle=trunc(hrolle)

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