There are various ways to do this. Here is one:
gen zuwpre= 1 if fallnum>10000 & f1_dispos==1003
foreach c of varlist f3_dispos- f3_elthaus {
capture confirm numeric variable `c'
if _rc == 0 {
replace `c'=. if zuwpre == 1
}
else replace `c' = "" if zuwpre == 1
}
drop zuwpre
Personally, I would dispense with the indicator variable:
foreach c of varlist f3_dispos- f3_elthaus {
capture confirm numeric variable `c'
if _rc == 0 {
replace `c'=. if fallnum>10000 & f1_dispos==1003
}
else replace `c' = "" if fallnum>10000 & f1_dispos==1003
}
Nick
[email protected]
Sergi VIDAL TORRE
I want to erase the information of my dataset for some individuals and
only for a set of variables.
I identified the individuals in a dummy var (zuwpre) and I used
'foreach' to a varlist as follows:
gen zuwpre= 1 if fallnum>10000 & f1_dispos==1003
foreach c of varlist f3_dispos- f3_elthaus {
replace `c'=. if zuwpre== 1
}
drop zuwpre
However, I get an error message because I have some string variables in
the varlist. Can anyone help me to improve this sintaxis to solve the
error.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/