Dear Stata users,
Thank you in advance for your time and help. I have some issues with nested loops on multiple imputations.
- When I regress y on x over several countries the following code works:
quietly levelsof country, local(countries)
foreach country of local countries{
mi estimate, esampvaryok post: regress y x i.d if country=="`country'"
outreg2 using results.xls, append nocons ctitle(`country')
}
- When I regress y on x over income quantiles (dhiq01 takes a value from 1 to 5) - but without the breakdown per country - this code works:
forvalues i=1/5{
mi estimate, esampvaryok post: regress y x i.d if dhiq01==`i'
outreg2 using results_inc.xls, nocons ctitle(Q `i') append
}
- But when it comes to run a nested loop, meaning I want to run regressions for each country over each income quintile, it does not work:
foreach country of local countries {
forvalues i=1/5 {
mi estimate, esampvaryok post: regress y x i.d if country=="`country'" & dhiq01==`i'
outreg2 using results_incCC.xls, nocons ctitle(`country' Q `i') append
}
}
It gives me error “mi estimate: omitted terms vary. The set of omitted variables or categories is not consistent between m=1 and m=2;…”
Noisily does not work. I tried to use forvalues also for countries (and, out of curiosity, using other variables) but it gives me the same error, suggesting something might be wrong with the syntax.
If I run a single estimation without the loop it works (mi estimate, esampvaryok post: regress y x i.d if country=="DE" & dhiq01==1).
Any help would be highly appreciated.
Thanks,
Nicola
Thank you in advance for your time and help. I have some issues with nested loops on multiple imputations.
- When I regress y on x over several countries the following code works:
quietly levelsof country, local(countries)
foreach country of local countries{
mi estimate, esampvaryok post: regress y x i.d if country=="`country'"
outreg2 using results.xls, append nocons ctitle(`country')
}
- When I regress y on x over income quantiles (dhiq01 takes a value from 1 to 5) - but without the breakdown per country - this code works:
forvalues i=1/5{
mi estimate, esampvaryok post: regress y x i.d if dhiq01==`i'
outreg2 using results_inc.xls, nocons ctitle(Q `i') append
}
- But when it comes to run a nested loop, meaning I want to run regressions for each country over each income quintile, it does not work:
foreach country of local countries {
forvalues i=1/5 {
mi estimate, esampvaryok post: regress y x i.d if country=="`country'" & dhiq01==`i'
outreg2 using results_incCC.xls, nocons ctitle(`country' Q `i') append
}
}
It gives me error “mi estimate: omitted terms vary. The set of omitted variables or categories is not consistent between m=1 and m=2;…”
Noisily does not work. I tried to use forvalues also for countries (and, out of curiosity, using other variables) but it gives me the same error, suggesting something might be wrong with the syntax.
If I run a single estimation without the loop it works (mi estimate, esampvaryok post: regress y x i.d if country=="DE" & dhiq01==1).
Any help would be highly appreciated.
Thanks,
Nicola