Hi everyone,
I'm trying to run a set of regressions for the levels of a string variable but I'm getting an invalid syntax error message.
Assume the variable with the classification information is "country", which has Argentina, Brazil, Chile, United States and so on.
I need to run the following code:
levelsof country, local(cnt)
gen error=.
foreach c of local cnt{
reg Y X1 X2 X3 if country==`c'
predict res, residuals
replace error=res if e(sample)
drop res
}
As I say, it returns the message invalid syntax. I've tried putting `c' as "`c'" but still get an error message where the countries are not found. It also seems to have problems dealing with longer names like United States which is comprised by two names (in this case I tried "`c'"). It must be something simple, but I'm unable to get a solution.
Any ideas on how to solve this?
I'm trying to run a set of regressions for the levels of a string variable but I'm getting an invalid syntax error message.
Assume the variable with the classification information is "country", which has Argentina, Brazil, Chile, United States and so on.
I need to run the following code:
levelsof country, local(cnt)
gen error=.
foreach c of local cnt{
reg Y X1 X2 X3 if country==`c'
predict res, residuals
replace error=res if e(sample)
drop res
}
As I say, it returns the message invalid syntax. I've tried putting `c' as "`c'" but still get an error message where the countries are not found. It also seems to have problems dealing with longer names like United States which is comprised by two names (in this case I tried "`c'"). It must be something simple, but I'm unable to get a solution.
Any ideas on how to solve this?
Comment