Skip to content

Instantly share code, notes, and snippets.

@paulgp
Created October 13, 2018 15:27
Show Gist options
  • Save paulgp/7e0c0ad9dee76c4ab8e475e1165d493f to your computer and use it in GitHub Desktop.
Save paulgp/7e0c0ad9dee76c4ab8e475e1165d493f to your computer and use it in GitHub Desktop.
Example code of outputting regression coefficients into latex
reghdfe `x' yearT_bk_2001 yearT_bk_2002 yearT_bk_2003 yearT_bk_2004 yearT_bk_2005 yearT_bk_2006 `post' [aweight=`weight' ] if year < $max_year & year > $min_year , vce(cluster state_id ) absorb(county_id i.yq ) dofadjustments(clusters)
local df_r = e(df_r)
local n`spec' = string(e(N), "%15.0fc")
local b`x'`spec' = string(`multiplier'*_b[`post2'], "%15.3fc")
local se`x'`spec' = string(`multiplier'*_se[`post2'], "%12.3fc")
local p = 2*ttail(`df_r',abs(_b[`post2']/_se[`post2']))
make_stars `p'
local star`x'`spec' `r(star)'
local spec = 2
reghdfe `x' yearT_bk_2001 yearT_bk_2002 yearT_bk_2003 yearT_bk_2004 yearT_bk_2005 yearT_bk_2006 `post' [aweight=`weight' ] if year < $max_year & year > $min_year, vce(cluster state_id ) absorb(county_id i.yq i.yq##c.(elas_*) ) dofadjustments(clusters)
local df_r = e(df_r)
local n`spec' = string(e(N), "%15.0fc")
local b`x'`spec' = string(`multiplier'*_b[`post2'], "%15.3fc")
local se`x'`spec' = string(`multiplier'*_se[`post2'], "%12.3fc")
local p = 2*ttail(`df_r',abs(_b[`post2']/_se[`post2']))
make_stars `p'
local star`x'`spec' `r(star)'
file open fh using "./Tables/employment_panel.tex", replace write
foreach x in lemp_nontr_strict_pop lemp_tradable_pop lemp_pop {
local label: variable label `x'
local line1 "\hspace{10pt} `label' & `m_`x'' "
local line2 " & (`sd_`x'') "
foreach column in 1 2 {
local line1 "`line1' & `b`x'`column''`star`x'`column''"
local line2 "`line2' & (`se`x'`column'')"
}
file write fh "`line1'" "\\" _n
file write fh "`line2'" "\\" _n
}
file write fh "\midrule" _n
local line3 " \multicolumn{2}{l}{Number of Observations} "
forvalues column= 1/2 {
local line3 "`line3' & \multicolumn{1}{c}{`n`column''} "
}
local line3 "`line3' "
file write fh "`line3'" "\\" _n
file close fh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment