Announcement

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

  • esttab interaction terms to latex

    I am running a regression with an interaction between the state and year

    Code:
    xi: xtreg y x i.fipstate*i.year, fe cluster(fips)
    eststo m1
    And when I run esttab to write the results to a latex file:

    Code:
    esttab m1 using "C:\Latex\interaction.tex", style(tex) label width(\textwidth)
    But it keeps writing it as "fipstate==# & year==#" in latex, which can't compile, because it thinks there is an extra column with that. I have tried adding
    Code:
    interaction(" $\times$ ")
    to the esttab command, but it does nothing.

  • #2
    I would no longer use the xi prefix. Recent version of Stata can use factor variable notation without it. Also make sure you have the most recent version of esttab (2.0.9 06feb2016).

    Here's a replicable example:

    Code:
    sysuse auto
    which esttab
    eststo: quietly regress price mpg i.foreign
    eststo: quietly regress price c.mpg##i.foreign
    esttab using "table.tex", varwidth(25) label nobaselevels interaction(" $\times$ ")style(tex) replace
    Here's my LaTeX file:

    Code:
    \documentclass{article}
    \begin{document}
    \input{table.tex}
    \end{document}
    This produces something like this when compiled:
    Click image for larger version

Name:	Screen Shot 2017-09-19 at 5.38.37 PM.png
Views:	1
Size:	52.6 KB
ID:	1411140

    Comment


    • #3
      Thanks Dimitriy. However, I noticed this works when the label option is specified. Otherwise, the interaction option does nothing as Colton flagged.

      Comment


      • #4
        mariofiorini That does seem to be an un(der)documented requirement, but not one that I find all that surprising. I have never made a LaTeX table in Stata where I did not want to use variable labels rather than variable names to label the coefficients since the ultimate goal is to make aesthetically pleasing tables. I also prefer to use estimation set titles rather than names. Moreover, Colton had that option in his original question.

        A quick workaround would be to re-label the variables with their names, though that would give you coefficients with labels like Foreign X mpg, which are mixture of value labels and variable names:

        Code:
        sysuse auto
        eststo clear
        
        foreach var of varlist price mpg foreign {
            lab var `var' "`var'"
        }
        
        eststo: quietly regress price mpg i.foreign
        eststo: quietly regress price c.mpg##i.foreign
        
        esttab using "table.tex", varwidth(25) nobaselevels style(tex) replace interaction(" X ") label


        Comment


        • #5
          hi, Dimitriy, I like the way your table look with double lines on the top and bottom, if you know what I mean. But with the same code, the table I got only has single lines. Any idea why?

          EDIT: in fact, it shows as double lined after texifying. So my question is solved.

          But a derived question: does anyone know how to make the top double line still double, but the bottom double line into single line?

          Originally posted by Dimitriy V. Masterov View Post
          mariofiorini That does seem to be an un(der)documented requirement, but not one that I find all that surprising. I have never made a LaTeX table in Stata where I did not want to use variable labels rather than variable names to label the coefficients since the ultimate goal is to make aesthetically pleasing tables. I also prefer to use estimation set titles rather than names. Moreover, Colton had that option in his original question.

          A quick workaround would be to re-label the variables with their names, though that would give you coefficients with labels like Foreign X mpg, which are mixture of value labels and variable names:

          Code:
          sysuse auto
          eststo clear
          
          foreach var of varlist price mpg foreign {
          lab var `var' "`var'"
          }
          
          eststo: quietly regress price mpg i.foreign
          eststo: quietly regress price c.mpg##i.foreign
          
          esttab using "table.tex", varwidth(25) nobaselevels style(tex) replace interaction(" X ") label

          Last edited by Larry Kong; 29 Aug 2019, 07:32.

          Comment


          • #6
            If you add the option -noisily-, you can see what's happening under the hood with esttab:

            Code:
            esttab using "table.tex", varwidth(25) nobaselevels style(tex) replace interaction(" X ") label noisily
            The double line is created in the postfoot() by repeating \hline twice, so you just need to edit this by removing the second \hline and add it as an option:

            esttab using "table2.tex", varwidth(25) nobaselevels style(tex) replace interaction(" X ") label ///
            postfoot(`"\hline"' `"\multicolumn{@span}{l}{\footnotesize \textit{t} statistics in parentheses}\"' `"\multicolumn{@span}{l}{\footnotesize @starlegend}\"' `"\end{tabular}"' `"}"')

            Putting the two tables side by side:

            Click image for larger version

Name:	Screen Shot 2019-08-29 at 5.44.51 PM.png
Views:	1
Size:	120.2 KB
ID:	1514372

            Comment

            Working...
            X