Hi all,
I am trying to compile a table with summary statistics using the template (code below) by Johannes Schmieder (see: https://sites.google.com/site/johannesschmieder/stata).
I have 2 categorical variables (marital status and educational attainment) for which I want to display the percentage of individuals in each category in the table. Therefore I created binary variables for each of the categories (variable names: educ_no educ_primary educ_sec_low educ_sec_up educ_post_sec educ_tert_first educ_tert_sec mar_married mar_partner mar_separ mar_divor mar_widow mar_never).
However, when I include more than 9 binary variables I get r(130) - "expression too long". The problem seems to be in the line where I define the local "binary": it can only have up to 9 arguments, as soon as I include 1 more I get the error. Is there a way in which I can define more than 9 variables as binary? I need this because I don't want the table to display the standard deviation for binary variables. Or should I look for another solution?
Thanks!
Coen
I am trying to compile a table with summary statistics using the template (code below) by Johannes Schmieder (see: https://sites.google.com/site/johannesschmieder/stata).
I have 2 categorical variables (marital status and educational attainment) for which I want to display the percentage of individuals in each category in the table. Therefore I created binary variables for each of the categories (variable names: educ_no educ_primary educ_sec_low educ_sec_up educ_post_sec educ_tert_first educ_tert_sec mar_married mar_partner mar_separ mar_divor mar_widow mar_never).
However, when I include more than 9 binary variables I get r(130) - "expression too long". The problem seems to be in the line where I define the local "binary": it can only have up to 9 arguments, as soon as I include 1 more I get the error. Is there a way in which I can define more than 9 variables as binary? I need this because I don't want the table to display the standard deviation for binary variables. Or should I look for another solution?
Thanks!
Coen
Code:
*Program for summary table capture program drop sumtable_share program define sumtable_share syntax , [file(str)] local size "\footnotesize" capture confirm file $out_files/`file' if _rc == 0{ rm $out_files/`file' } use $working_data/SHAREsummary_test.dta, clear local binary "educ_no","educ_primary","educ_sec_low","educ_sec_up", /// "educ_post_sec","educ_tert_first","educ_tert_sec", "d_early_ret", "d_normal_ret", /// "mar_married", "mar_partner", "mar_separ", "mar_divor", "mar_widow", "mar_never" local outcomes reurod local controls ragey hittot radla riadlza d_early_ret d_normal_ret /// mar_married mar_partner mar_separ mar_divor mar_widow mar_never local education educ_no educ_primary educ_sec_low /// educ_sec_up educ_post_sec educ_tert_first educ_tert_sec g full = 1 g smpl1 = full & ragender==1 & ragey>=50 & ragey<=70 g smpl2 = full & ragender==1 & ragey>=50 & ragey<=70 & country_area==1 g smpl3 = full & ragender==1 & ragey>=50 & ragey<=70 & country_area==2 g smpl4 = full & ragender==1 & ragey>=50 & ragey<=70 & country_area==3 g smpl5 = full & ragender==2 & ragey>=50 & ragey<=70 g smpl6 = full & ragender==2 & ragey>=50 & ragey<=70 & country_area==1 g smpl7 = full & ragender==2 & ragey>=50 & ragey<=70 & country_area==2 g smpl8 = full & ragender==2 & ragey>=50 & ragey<=70 & country_area==3 local conditions "smpl1" "smpl2" "smpl3" "smpl4" "smpl5" "smpl6" "smpl7" "smpl8" * local colhead0 & (1) & (2) & (3) & (4) local colhead1 & All & North & West & South & All & North & West & South local colhead2 & Men & Men & Men & Men & Women & Women & Women & Women local cols : word count "`conditions'" local cols = `cols'+1 writeln $out_files/`file' "\begin{table}[htbp]\centering " writeln $out_files/`file' "\caption{Summary Table of Share Data \label{tab:sumShare}}" writeln $out_files/`file' "\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}" writeln $out_files/`file' "\begin{threeparttable} " writeln $out_files/`file' "\begin{tabular}{l *{`=`cols'-1'}{c}} " writeln $out_files/`file' "\toprule " * writeln $out_files/`file' " `colhead0' \\" writeln $out_files/`file' " `colhead1' \\" writeln $out_files/`file' " `colhead2' \\" local paneltitles "Outcome Demographics Education" local panels outcomes controls education foreach panel in `panels' { local ppos: list posof "`panel'" in local(panels) local paneltit: word `ppos' of `paneltitles' writeln $out_files/`file' "\midrule" writeln $out_files/`file' "\multicolumn{`cols'}{l}{\textbf{`size'{`paneltit'}}} \\ " foreach v in ``panel'' { local vl : variable label `v' local linemean `vl' local linesd foreach c in "`conditions'" { if "`c'"=="full" & (("`panel'"=="dwscontrols") | ("`=substr("`v'",1,2)'"=="lj")) { local linemean `linemean' & local linesd `linesd' & continue } qui sum `v' if `c' sigdigits a2 `=r(mean)' local mean: disp `fmt' `=r(mean)' local linemean `linemean' & `mean' sigdigits a2 `=r(sd)' local sd: disp `fmt' `=r(sd)' local linesd `linesd' & `=cond(`sd'!=.,"[`=ltrim("`sd'")']","`sd'")' // ,`=r(N)' } writeln $out_files/`file' "`linemean' \\" if !inlist("`v'","`binary'") writeln $out_files/`file' "`linesd' \\" } } writeln $out_files/`file' "\midrule " local j 1 local countline foreach c in "`conditions'" { count if `c' local count`j' = r(N) local countline `countline' & `count`j++'' } writeln $out_files/`file' "Number of observations `countline' \\ " writeln $out_files/`file' "\bottomrule " writeln $out_files/`file' "\end{tabular}" writeln $out_files/`file' "\textit{Source}: SHARE waves 1, 2, 4, 5 and 6" writeln $out_files/`file' "\end{threeparttable} " writeln $out_files/`file' "\end{table}" end // program sumShare
Comment