Hi everyone,
I’m facing an issue with the keep option in esttab when trying to include interaction terms generated dynamically in a loop. Here's what I'm doing: I have a list of variables stored in a local macro (variable). For each variable in the list, I generate an interaction term with another variable (dummy_child_aspiration) inside a foreach loop. I then estimate a probit regression for each variable and its interaction term. I save the results with eststo for each regression. After the loop, I use esttab to create a combined table, specifying the variables I want to keep with the keepoption:
local variable "dummy_Q16a dummy_Q16b dummy_Q16c dummy_Q16d dummy_Q16e"
foreach x of local variable {
local clean_name = subinstr("`x'", "_", "", .)
gen `x'_inter = `x' * dummy_child_aspiration
eststo regr`clean_name': probit child_succeeds avg_skill_imp_index `x' `x'_inter dummy_child_wanted_succeed sex inter_firstborn_male dummy_first_born log_age_child dummy_child_aspiration dummy_importance_edu i.Macro_region dummy_sector_services_manu dummy_class_large dummy_female_ceo log_age_ceo nchildren, cluster(id)
esttab regr`clean_name' using "$tables/basic_index_var.tex", replace ///
star(* 0.10 ** 0.05 *** 0.01) ///
keep(avg_skill_imp_index dummy_child_wanted_succeed sex inter_firstborn_male log_age_child ///
dummy_child_aspiration dummy_female_ceo dummy_importance_edu log_age_ceo nchildren `x' `x'_inter) ///
compress scalars("N Observations") sfmt("%9.0fc")
}
esttab using "$tables/final_results_inter_aspiration1_Q16.tex", keep(avg_skill_imp_index dummy_child_wanted_succeed sex inter_firstborn_male log_age_child dummy_child_aspiration dummy_female_ceo dummy_importance_edu log_age_ceo nchildren `x' `x'_inter) addnotes("FE omitted: i.Macro_region dummy_sector_services_manu dummy_class_large") cells(b(star fmt(3)) se(par)) stats(N , fmt(3 3)) replace tex
I then get this error: coefficient _inter not found r(111);
However, if I omit the keep option, the table is generated correctly, and both the variable (\x') and its interaction term (`x'_inter`) appear in the output. What I suspect: The macro \x'_interis not expanded correctly withinkeep`. esttab may not recognize the dynamically generated variable names in keep.
Question: How can I properly include the interaction terms dynamically in the keep option of esttab? Thank you for any suggestions!
I’m facing an issue with the keep option in esttab when trying to include interaction terms generated dynamically in a loop. Here's what I'm doing: I have a list of variables stored in a local macro (variable). For each variable in the list, I generate an interaction term with another variable (dummy_child_aspiration) inside a foreach loop. I then estimate a probit regression for each variable and its interaction term. I save the results with eststo for each regression. After the loop, I use esttab to create a combined table, specifying the variables I want to keep with the keepoption:
local variable "dummy_Q16a dummy_Q16b dummy_Q16c dummy_Q16d dummy_Q16e"
foreach x of local variable {
local clean_name = subinstr("`x'", "_", "", .)
gen `x'_inter = `x' * dummy_child_aspiration
eststo regr`clean_name': probit child_succeeds avg_skill_imp_index `x' `x'_inter dummy_child_wanted_succeed sex inter_firstborn_male dummy_first_born log_age_child dummy_child_aspiration dummy_importance_edu i.Macro_region dummy_sector_services_manu dummy_class_large dummy_female_ceo log_age_ceo nchildren, cluster(id)
esttab regr`clean_name' using "$tables/basic_index_var.tex", replace ///
star(* 0.10 ** 0.05 *** 0.01) ///
keep(avg_skill_imp_index dummy_child_wanted_succeed sex inter_firstborn_male log_age_child ///
dummy_child_aspiration dummy_female_ceo dummy_importance_edu log_age_ceo nchildren `x' `x'_inter) ///
compress scalars("N Observations") sfmt("%9.0fc")
}
esttab using "$tables/final_results_inter_aspiration1_Q16.tex", keep(avg_skill_imp_index dummy_child_wanted_succeed sex inter_firstborn_male log_age_child dummy_child_aspiration dummy_female_ceo dummy_importance_edu log_age_ceo nchildren `x' `x'_inter) addnotes("FE omitted: i.Macro_region dummy_sector_services_manu dummy_class_large") cells(b(star fmt(3)) se(par)) stats(N , fmt(3 3)) replace tex
I then get this error: coefficient _inter not found r(111);
However, if I omit the keep option, the table is generated correctly, and both the variable (\x') and its interaction term (`x'_inter`) appear in the output. What I suspect: The macro \x'_interis not expanded correctly withinkeep`. esttab may not recognize the dynamically generated variable names in keep.
Question: How can I properly include the interaction terms dynamically in the keep option of esttab? Thank you for any suggestions!
Comment