Hi
I am coding survey responses for analysis. I have one group of columns, which I need to encode, and then actually merge into one column. Namely, respondents could indicate a country as a destination, and the survey codes each country as a column. Q37_13 (Algeria) through Q37_207 (Zimbabwe). I need a destination variable. Right now, I have 194 columns of string variables, one per country
I uploaded a screenshot for reference.
I tried writing a loop command to either destring or encode, but I get the r(198) error each time.
Here are various attempts:
foreach var of Q37_* {
encode 'var', gen(N_var)
}
invalid syntax
r(198);
foreach var of varlist Q37_* {
destring 'var', force
}
' invalid name
r(198);
. foreach var of Q37_13 - Q37_207 {
2. encode 'var', gen('var'N)
3. }
invalid syntax
r(198);
Once I decode, I will have to create one variable out of the 194 columns, so if there is a different approach (like combining them first?) I am open to that too
Thank you for your help!
Natalie

I am coding survey responses for analysis. I have one group of columns, which I need to encode, and then actually merge into one column. Namely, respondents could indicate a country as a destination, and the survey codes each country as a column. Q37_13 (Algeria) through Q37_207 (Zimbabwe). I need a destination variable. Right now, I have 194 columns of string variables, one per country
I uploaded a screenshot for reference.
I tried writing a loop command to either destring or encode, but I get the r(198) error each time.
Here are various attempts:
foreach var of Q37_* {
encode 'var', gen(N_var)
}
invalid syntax
r(198);
foreach var of varlist Q37_* {
destring 'var', force
}
' invalid name
r(198);
. foreach var of Q37_13 - Q37_207 {
2. encode 'var', gen('var'N)
3. }
invalid syntax
r(198);
Once I decode, I will have to create one variable out of the 194 columns, so if there is a different approach (like combining them first?) I am open to that too
Thank you for your help!
Natalie
Comment