Statalist The Stata Listserver


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

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


From   "Richard Atkins" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   Re: st: Another spss do if-translation-problem
Date   Tue, 31 Oct 2006 11:18:02 +0000

Hi Julia

There is a logic flaw. The SPSS statement is three exclusive operations
but the Stata statements are non-exclusive.

SPSS
> 				do if hrolle<20.
> 				compute hrolle=hrolle-10.
> 				else if hrolle < 30.
> 				compute hrolle=hrolle-20.
> 				else.
> 				compute hrolle=hrolle-30.
> 				end if.
> 				exec.

Stata
> > 	replace hrolle=hrolle-10 if hrolle<20
> > 	replace hrolle=hrolle-20 if hrolle<30
> > 	replace hrolle=hrolle-30 if hrolle>=30

A value of 19 would 'hit' the -10 operation in SPSS but both the -10
and then the -20 operations is Stata.

A slightly longwinded but transparent way to rewrite this would be:

gen adjustment=0
replace adjustment = -10 if hrolle<20
replace adjustment = -20 if hrolle<30
replace adjustment = -30 if hrolle>=20
replace hrolle = hrolle+adjustment
drop adjustment

Regards, Richard A.

www.richardatkins.co.uk 



>>> Schneider Julia <[email protected]> 31/10/2006 09:50 >>>

> Good morning,
> 
> 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?
> 
> Thanx for your help!
> Julia
> 
> ****
> 
> 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/
*
*   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