Announcement

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

  • How to output variable labels -- want transposed table in latex

    Hello all,

    I am referencing this older thread http://www.statalist.org/forums/foru...37#post1328437 that provides a solution to creating a transposed table (independent and dependent variables switched)
    I would like to display variable labels instead of variable names in a output table, using estab and estout. In other words: the code below outputs a table with rows titled "Route1", "Route2" etc. Instead, these rows should automatically display the respective variable label. (The second part of the question is likely going to output the same table to a .tex (Latex) format).
    Thank you in advance for any suggestions!

    Code:
    sysuse auto, clear
    eststo clear
    matrix drop _all
    
    levelsof rep78, local(levelrep78)
    di "`levelsrep78'"
    
    foreach l of local levelrep78 {
        di "rep78: `l'"
        capture noisily
        reg p turn head if rep78==`l'
        eststo Route`l', title(`""`levrep'""')
        loc titl `"`titl' "`levrep'""'
        }
    
    esttab using r, p scalars(F df_m df_r) keep( turn ) replace
    mat list r(coefs)
    mat rename r(coefs) foo
    mat list foo
    
    esttab matrix(foo, transpose) using filename, replace
    estout mat(foo, fmt(3 3) transpose) using Table4.tex,  label replace style(tex)  collabels(none)

  • #2
    estout is a package from SSC. The FAQ asks you to mention this.

    There are some errors in your code.
    Code:
    di "`levelsrep78'"
    should be
    Code:
    di "`levelrep78'"
    The macro "levrep" in the commands below is not defined.
    Code:
    eststo Route`l', title(`""`levrep'""')
    loc titl `"`titl' "`levrep'""'
    You don't seem to do anything with the macro "titl".

    I am not sure what exactly you are trying to accomplish but the variable label can be extracted with this command:
    Code:
    local rep78lab : var lab rep78
    di "`rep78lab'"

    Comment


    • #3
      Thanks for the reply!
      Right, those errors are not helping.
      The cleaned version below outputs a table. Each row displays a variable name (Route1, Route2, ...). I am trying to display the associated variable label--not the variable name--in each row. Instead of "Route1" it should read "esample() from estimates store." Using "esttab, [...] label" to achieve this does not appear to work when the table is transposed.

      Code:
      sysuse auto, clear
      eststo clear 
      matrix drop _all
      
      levelsof rep78, local(levelrep78)
      di "`levelsrep78'"
      
      foreach l of local levelrep78 {
          di "rep78: `l'"
          capture noisily
          eststo Route`l': reg p turn head if rep78==`l'
      }
      
      esttab using r, p scalars(F df_m df_r) keep( turn ) replace 
      mat list r(coefs) 
      mat rename r(coefs) foo
      mat list foo
      
      esttab matrix(foo, transpose) using filename, replace

      Comment


      • #4
        I don't know if there is a way to do this with esttab but you can change the text in the saved files with filefilter.
        Code:
        help filefilter
        filefilter filename.txt filename2.txt, from("Route1") to("esample() from estimates store") replace

        Comment


        • #5
          That's helpful, thank you!

          Comment

          Working...
          X