Announcement

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

  • dependent variable spanning many columns in esttab

    Hello everyone. I am using esttab to make a table (in .tex) in which I have several columns in a row with the same dependent variable. I would like to have the dependent variable span multiple columns. I know I can use the "mgroups" command to do this, but the only way I can figure out how to tell stata the names of the dependent variables is to enter them manually ("price" and "weight" in the code below).

    sysuse auto, clear
    local i=1
    foreach var of varlist weight price{
    quietly reg `var' mpg
    estimates store m`i', title("`:variable label `var''")
    quietly reg `var' mpg foreign
    estimates store m`i', title("`:variable label `var''")
    local i=`i'+1
    }
    esttab m1 m2 m3 m4 using "C:\Users\rmheath\Documents\example.tex", tex label replace ///
    nomtitle collabels(none) mgroups("weight" "price", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

    I would love to find a way to tell mgroups to reference the title of the estimation, so that I don't have to go back manually and change the headings listed in mgroups if I change the dependent variables in a regression. Can anyone figure out how to do this?

    thank you in advance if anyone can help!
    Rachel

  • #2
    esttab is from Stata Journal, authored by Ben Jann. You can use a local macro to store the variable name.

    Code:
    sysuse auto, clear
    local i=1
    foreach var of varlist weight price{
    quietly reg `var' mpg
    estimates store m`i', title("`:variable label `var''")
    quietly reg `var' mpg foreign
    estimates store m`i', title("`:variable label `var''")
    local dv`i' "`var'"
    local i=`i'+1
    }
    esttab m1 m2 m3 m4 using "C:\Users\rmheath\Documents\example.tex", tex label replace ///
    nomtitle collabels(none) mgroups("`dv1'" "`dv2'", pattern(1 0 1 0)  ///
    prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

    Comment


    • #3
      Oh, great idea, thanks!

      Comment


      • #4
        Is it possible to use mgroups for only certain columns? For example, in the example above, if there was a fifth group which did not have a group title.

        Comment


        • #5
          Originally posted by Adrienne Wold View Post
          Is it possible to use mgroups for only certain columns? For example, in the example above, if there was a fifth group which did not have a group title.
          Don't you just omit one?

          Code:
          esttab m1 m2 m3 m4 m5, tex label replace ///
          nomtitle collabels(none) mgroups("`dv1'" "`dv2'" " ", pattern(1 0 1 0 1)  ///
          prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

          Comment

          Working...
          X