In the topic entitled "regression by city and year", which I created the in the forum in March, I got help to build a syntax that would allow me to apply the command "hoi" for each state (uf) and year (ano) on a database composed of 27 states and 9 years, whereas logistic regression that the command "hoi" generates would consist of one outcome and nine predictors. The code I'm using is as follows:
I repeated this seven times code because I needed to do the same thing for seven different outcomes.
At the moment I need to adjust the code to apply the command "hoi" and capture the results for five specific years and if possible for all outcomes at once, so it is not necessary for me to repeat the new code seven times.
I would like your help again.
Thanks in advance.
capture postutil clear
postfile handle ufs ano hoi_1 d_1 p_1 using hoi_agua, replace
local predictors presmae metrop area logrenpcdef nmorad refsexo refraca medescresp difescresp
local outcomes agua
levelsof uf, local(ufs)
foreach c of local ufs {
levelsof ano if uf == `c', local(anos)
foreach y of local anos {
display "uf = `c', ano = `y'"
foreach o of varlist `outcomes' {
capture noisily hoi `o' `predictors' [fw = pesopes] ///
if uf == `c' & ano == `y', format(%9.3f) estimates decomp1
if c(rc) == 2000 { // hoi FAILED DUE TO NO OBSERVATIONS
display "Nao ha observacoes ou o outcome nao e dicotomico `o': analise ignorada"
}
else if c(rc) != 0 { // SOME OTHER ERROR AROSE ATTEMPTING hoi
display in red "Erro encontrado ao executar o ioh com o outcome `o', uf = `c', ano = `y'"
exit c(rc) // SHOW ERROR CODE AND STOP
}
if c(rc) ==0 post handle (`c') (`y') (`r(hoi_1)') (`r(d_1)') (`r(p_1)')
}
}
}
postclose handle
postfile handle ufs ano hoi_1 d_1 p_1 using hoi_agua, replace
local predictors presmae metrop area logrenpcdef nmorad refsexo refraca medescresp difescresp
local outcomes agua
levelsof uf, local(ufs)
foreach c of local ufs {
levelsof ano if uf == `c', local(anos)
foreach y of local anos {
display "uf = `c', ano = `y'"
foreach o of varlist `outcomes' {
capture noisily hoi `o' `predictors' [fw = pesopes] ///
if uf == `c' & ano == `y', format(%9.3f) estimates decomp1
if c(rc) == 2000 { // hoi FAILED DUE TO NO OBSERVATIONS
display "Nao ha observacoes ou o outcome nao e dicotomico `o': analise ignorada"
}
else if c(rc) != 0 { // SOME OTHER ERROR AROSE ATTEMPTING hoi
display in red "Erro encontrado ao executar o ioh com o outcome `o', uf = `c', ano = `y'"
exit c(rc) // SHOW ERROR CODE AND STOP
}
if c(rc) ==0 post handle (`c') (`y') (`r(hoi_1)') (`r(d_1)') (`r(p_1)')
}
}
}
postclose handle
At the moment I need to adjust the code to apply the command "hoi" and capture the results for five specific years and if possible for all outcomes at once, so it is not necessary for me to repeat the new code seven times.
I would like your help again.
Thanks in advance.