Hello,
I have a dataset which includes a specific questionnaire (105 variables, all numeric) and I would like to generate a variable data with 0 unless any of the 105 variables has a value than I would like a 1. All 105 variables end with _CLEAN, the dataset contains more variables, but this can be used as an identifier. I thought it would be fasted to use a foreach and replace command.
Stata returns an error : '*_CLEAN invalid name'
But I don't understand why it's an invalid name as I used the following loop without any problems.
Any guidance would be much appreciated!
Kind regards,
Rosa
I have a dataset which includes a specific questionnaire (105 variables, all numeric) and I would like to generate a variable data with 0 unless any of the 105 variables has a value than I would like a 1. All 105 variables end with _CLEAN, the dataset contains more variables, but this can be used as an identifier. I thought it would be fasted to use a foreach and replace command.
Code:
gen data =0 foreach x of *_CLEAN { replace data = 1 if `x' <10 }
But I don't understand why it's an invalid name as I used the following loop without any problems.
Code:
foreach x in *_CLEAN{ mdesc `x' }
Any guidance would be much appreciated!
Kind regards,
Rosa
Comment