Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with columns labelling using eststo

    Hi,

    I'm using Stata 15.1.

    I use the following code to obtain a Latex table reporting the mean for a set of variables, in 8 columns (with the first 4 columns reporting stats for girls, the last 4 for boys).

    The 1st column reports the mean of each variable for the whole girls' sample, the 2nd one for the girls from 10 to 14 years old, the 3rd one for the girls from 15 to 19 years old, and the last one for the girls from 20 to 24 years old. Same for the boys.

    Nevertheless, the titles of my 8 columns remain "Total" in the Latex output file. Any idea why ?

    est clear

    global vars drawbacks_marr num_drawbacks_marr mst drawbacks_marr_child violence lost_child early_wid

    ***Girls
    eststo m1: estpost sum $vars if sex==1
    eststo m2: estpost sum $vars if sex==1 & age_ADO==0
    eststo m3: estpost sum $vars if sex==1 & age_ADO==1
    eststo m4: estpost sum $vars if sex==1 & age_ADO==2

    ***Boys
    eststo m5: estpost sum $vars if sex==0
    eststo m6: estpost sum $vars if sex==0 & age_ADO==0
    eststo m7: estpost sum $vars if sex==0 & age_ADO==1
    eststo m8: estpost sum $vars if sex==0 & age_ADO==2


    *** Export to Latex format
    esttab m1 m2 m3 m4 m5 m6 m7 m8 using "$output_girls/Table1.tex", replace ///
    cells("mean(pattern(1 1 1 1 1 1) fmt(2))") ///
    collabels("Total" "10-14 ans" "15-19 ans" "20-24 ans" "Total" "10-14 ans" "15-19 ans" "20-24 ans") ///
    star(* 0.10 ** 0.05 *** 0.01) ///
    label booktabs nonum gaps noobs compress

  • #2
    eststo, esttab, and estpost are community-contributed commands, as the FAQ (https://www.statalist.org/forums/help) recommends mentioning. In another recent post you made about esttab syntax, you produced a reproducible example after being asked, and it'd be worth producing one with each post.

    I don't have expertise with esttab/estout, but it looks like you need to change the column labels to model labels, something like this:
    Code:
    esttab m1 m2 m3 m4 m5 m6 m7 m8 using "Table1.tex", replace ///
    cells("mean(fmt(2))") ///
    mgroups("Male" "Female", pattern(1 0 0 0 1 0 0 0 0)) ///
    mlabels("All" "10-14 ans" "15-19 ans" "20-24 ans" "All" "10-14 ans" "15-19 ans" "20-24 ans") ///
    collabels(none) ///
    label booktabs nonum gaps noobs compress
    Unfortunately, the male/female group labels aren't centered over the relevant four columns, but estout's span option is inscrutable to me, so I don't know how to fix that. You can always omit them.


    I apologize if this isn't helpful to you personally, but for anyone with access to Stata 17, the new table functionality is a reasonable option. Here's an example using randomly generated values:
    Code:
    * create demonstration data
    clear all
    set obs 30
    gen sex = rbinomial(1,.5)
    gen age_ADO = runiformint(0,2)
    gen dvar1 = runiformint(0,10)
    gen dvar2 = runiformint(0,10)
    
    * code below applicable to actual data 
    label define agegrps 0 "10-14 ans" 1 "15-19 ans" 2 "20-24 ans" -1 "Total", replace
    label values age_ADO "agegrps"
    
    label define sexlabels 1 "Female" 0 "Male"
    label values sex "sexlabels"
    
    local vars dvar1 dvar2 // whatever variables you want means for
    collect: table () (sex age_ADO) , stat(mean `vars') nformat(%10.2f) totals(sex) 
    collect style header age_ADO, title(hide)
    collect style header sex, title(hide)
    collect export Table1.tex, replace
    Output:
    Code:
    \begin{table}[!h]
    \centering
    \begin{tabular}{lllllllll}
    \cline{1-9}
    \multicolumn{1}{c}{} &
      \multicolumn{4}{|c}{Male} &
      \multicolumn{4}{c}{Female} \\
    \multicolumn{1}{c}{} &
      \multicolumn{1}{|r}{10-14 ans} &
      \multicolumn{1}{r}{15-19 ans} &
      \multicolumn{1}{r}{20-24 ans} &
      \multicolumn{1}{r}{Total} &
      \multicolumn{1}{r}{10-14 ans} &
      \multicolumn{1}{r}{15-19 ans} &
      \multicolumn{1}{r}{20-24 ans} &
      \multicolumn{1}{r}{Total} \\
    \cline{1-9}
    \multicolumn{1}{l}{dvar1} &
      \multicolumn{1}{|r}{5.63} &
      \multicolumn{1}{r}{4.54} &
      \multicolumn{1}{r}{5.56} &
      \multicolumn{1}{r}{5.13} &
      \multicolumn{1}{r}{6.18} &
      \multicolumn{1}{r}{6.42} &
      \multicolumn{1}{r}{5.57} &
      \multicolumn{1}{r}{6.13} \\
    \multicolumn{1}{l}{dvar2} &
      \multicolumn{1}{|r}{5.88} &
      \multicolumn{1}{r}{5.15} &
      \multicolumn{1}{r}{6.22} &
      \multicolumn{1}{r}{5.67} &
      \multicolumn{1}{r}{6.18} &
      \multicolumn{1}{r}{4.83} &
      \multicolumn{1}{r}{3.57} &
      \multicolumn{1}{r}{5.03} \\
    \cline{1-9}
    \end{tabular}
    \end{table}
    Click image for larger version

Name:	table.jpg
Views:	1
Size:	29.5 KB
ID:	1712996

    Comment

    Working...
    X