I tried to use the following command, but it does not work.
gen preta_c=.
xtset c_id_new year
tempvar ta
levelsof two_sic_code,local(levels)
foreach x of local levels{
foreach z of numlist 2009/2020{
capture bys country_id: reg ta mdj_x1 mdj_x2 mdj_x3 if two_sic_code==`x' & year==`z'
if !_rc {
predict `ta'
replace preta_c=`ta' if e(sample)
drop `ta'
}
}
}
gen preta_c=.
xtset c_id_new year
tempvar ta
levelsof two_sic_code,local(levels)
foreach x of local levels{
foreach z of numlist 2009/2020{
capture bys country_id: reg ta mdj_x1 mdj_x2 mdj_x3 if two_sic_code==`x' & year==`z'
if !_rc {
predict `ta'
replace preta_c=`ta' if e(sample)
drop `ta'
}
}
}
Comment