Julia wrote:
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?
....
------------------------------------------------------------------
Julia,
You have seen a couple of suggestions. However: It is complicated and
dangerous to modify a variable (in SPSS, Stata, or any other package)
while at the same time letting the calculations depend on the value of
the same variable. And it becomes impossible to check afterwards whether
things were done as intended. Here is a suggestion that does not modify
the original variable (hrolle):
clear
set obs 10000
gen caseid=_n
gen hrolle=caseid/30
gen x1=hrolle-200
replace x1=hrolle-100 if hrolle<200
gen x2=x1-30
replace x2=x1-20 if hrolle<30
replace x2=x1-10 if hrolle<20
gen rolle=int(x2)
Note that the reversed the sequence of calculations in Stata corresponds
to what is obtained by SPSS' do if ... else if ... else construct.
For a simple visual check:
twoway (scatter rolle hrolle)
Hope this helps
Svend
__________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone: +45 8942 6090
Home: +45 8693 7796
Email: [email protected]
__________________________________________
*
* 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/