Announcement

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

  • esttab and LaTeX

    I am formatting regression tables which are being produced by esttab and then moved into a LaTeX environment. I have two questions:

    1. I want to use refcat to create category headings for my variables. The current syntax runs with no errors in Stata and imports without an error in LaTex, but the formatting isn't visible. The desired effect is something that looks like the following:

    Child Age (months)
    indent here 12-23
    indent here 24-35
    indent here 36-59
    indent here 48-59

    I'm currently using the following syntax:

    Code:
    quietly svy: logistic fail i.treat2 c.MEI2 c.MEI2#i.treat2 i. female i.mon_age_bin i.v127 i.v149 i.rural i.amp i.year2 i.ADM1_CODE i.year2#i.ADM1_CODE   
    est store A
    
    quietly svy, subpop(urban): logistic fail i.treat2 c.MEI2 c.MEI2#i.treat2 i. female i.mon_age_bin i.v127 i.v149 i.amp i.year2 i.ADM1_CODE i.year2#i.ADM1_CODE
    est store B
    
    quietly svy, subpop(rural): logistic fail i.treat2 c.MEI2 c.MEI2#i.treat2 i. female i.mon_age_bin i.v127 i.v149 i.amp i.year2 i.ADM1_CODE i.year2#i.ADM1_CODE
    est store C
    
    foreach v of varlist * {
        label variable `v' `"\hspace{0.1cm} `: variable label `v''"'
        }
    
    esttab A B C using "Y:\DolanChapter_5\Analysis\Stata Output\Final Analysis\TableA.tex", replace ///
    nobaselevels longtable  eform label booktabs star(* 0.10 ** 0.05 *** 0.01) ///  
    title("Main results from child-level logistic model") mtitle("Combined" "Urban" "Rural") ///
    refcat(2"\emph{Age}")
    An image of the resulting output is attached.

    2. How do I use esttab effectively to a)drop the reference categories and b) the fields that I don't want to use. For example, '99'.

    I tried the following:

    Code:
    drop [_cons]
    drop [gender*]
    drop [_I*]


    Attached Files

  • #2
    Everything but the indenting of the value labels is pretty easy. The trick is pretending you have a second language which will contain the LaTeX-friendly variable and value labels:

    Code:
    capture set trace off
    label drop _all
    set more off
    webuse lbw
    
    /* (1) Get a list of variables with value labels to loop over and modify */
    label language original, new copy
    label language indented, new copy
    ds, has(vallabel)
    foreach var of varlist `r(varlist)' {
        local val_label: value label `var'
        label copy `val_label' `val_label'_indented
        
        /* (2) Loop over value label for each variable & insert a LaTeX h-space */
        qui levelsof `var'
        foreach v of numlist `r(levels)' {
            local old_val_lab: label `val_label' `v'
            label define `val_label'_indented `v' `"\hspace{0.2cm}`old_val_lab'"', modify
        }
        // label drop `val_label'
         lab val `var' `val_label'_indented
    }
    
    label var low "Birthweight $<$ 2500g"
    
    /* (3) Switch Back To Original Labels SP Output Looks OK */
    label language original
    label list
    logistic low age lwt i.race smoke ptl ht ui, coefl
    estimates store log
    
    /* (3) Switch Back To Indented Labels for Table */
    label language indented
    esttab log using "logistic.tex", replace ///
    nobaselevels longtable  eform label booktabs star(* 0.10 ** 0.05 *** 0.01) ///  
    title("Main Results") mtitle("Logistic") ///
    refcat(2.race "\emph{Race:}", nolab) ///
    drop(lwt smoke ptl ht ui _cons)
    
    label language original
    This will produce a table that looks like this:

    Click image for larger version

Name:	Screen Shot 2016-06-20 at 3.25.36 PM.png
Views:	1
Size:	28.6 KB
ID:	1346100

    Comment

    Working...
    X