Hello,
i am using loop for running regression on multiple units (i.e. countries), however, it seems like some countries do not have sufficient observations to run the regression.
I tried using commands as below, however, it still has same issue.
I would like to run the regressions for those who have sufficient observations (i.e. ignore if insufficient obs).
Can someone help me solve this issue?
i am using loop for running regression on multiple units (i.e. countries), however, it seems like some countries do not have sufficient observations to run the regression.
I tried using commands as below, however, it still has same issue.
I would like to run the regressions for those who have sufficient observations (i.e. ignore if insufficient obs).
Can someone help me solve this issue?
Code:
loc job JCR NJCR JDR JCR2 NJCR2 JDR2
levelsof country, local(countries)
foreach c of local countries{
if c(rc) == 0 {
noi di _n "Country: `c'"
foreach var of local job {
loc model_name "5-year `var'"
loc FElbl13 i.cty#i.year i.cty#i.ind_a38
loc FElbl24 i.cty#i.ind_a38#i.year
* Column (1)
reghdfe `var'_5L ib3.p_LogLP_VA LogL_av if country == "`c'" [aw=weightvar], a(`FElbl13') vce(cluster i.cty#i.ind_a38) allbaselevels
levelsof country if e(sample)
local n_countries = `r(r)'
levelsof ind_a38 if e(sample)
local n_inds = `r(r)'
outreg2 using "5y_`var'_reg.xls", append ctitle(`model_name') label ///
addtext(Fixed effects, `FElbl13', Countries, `n_countries', Industries, `n_inds')
* Column (2)
reghdfe `var'_5L ib3.p_LogLP_VA LogL_av if country == "`c'" [aw=weightvar], a(`FElbl24') vce(cluster i.cty#i.ind_a38) allbaselevels
levelsof country if e(sample)
local n_countries = `r(r)'
levelsof ind_a38 if e(sample)
local n_inds = `r(r)'
outreg2 using "5y_`var'_reg.xls", append ctitle(`model_name') label ///
addtext(Fixed effects, `FElbl13', Countries, `n_countries', Industries, `n_inds')
* Column (3)
reghdfe `var'_5L F1LogLP_VA_av ib3.p_LogLP_VA `var'_1L LogL_av if country == "`c'" [aw=weightvar], a(`FElbl13') vce(cluster i.cty#i.ind_a38) allbaselevels
levelsof country if e(sample)
local n_countries = `r(r)'
levelsof ind_a38 if e(sample)
local n_inds = `r(r)'
outreg2 using "5y_`var'_reg.xls", append ctitle(`model_name') label ///
addtext(Fixed effects, `FElbl13', Countries, `n_countries', Industries, `n_inds')
* Column (4)
reghdfe `var'_5L F1LogLP_VA_av ib3.p_LogLP_VA `var'_1L LogL_av if country == "`c'" [aw=weightvar], a(`FElbl24') vce(cluster i.cty#i.ind_a38) allbaselevels
levelsof country if e(sample)
local n_countries = `r(r)'
levelsof ind_a38 if e(sample)
local n_inds = `r(r)'
outreg2 using "5y_`var'_reg.xls", append ctitle(`model_name') label ///
addtext(Fixed effects, `FElbl13', Countries, `n_countries', Industries, `n_inds')
}
} // end of job loop
else if !inlist(c(rc), 2000, 2001) {
display as error "Unexpected error in regression"
exit c(rc)
}
}

It's exactly what I was looking for, thanks again for your suggestion&insights
Comment