Announcement

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

  • Error while stacking multiple regression outputs in a .tex file

    Hi,

    I'm trying to export multiple regression outputs to .tex and creating a stack of multiple panels, as shown in https://medium.com/@linglp/nice-regr...a-17d3895befd2

    I'm following the exact same code as in the blog:

    Code:
    use "$data\data.dta",clear
    
    /*panel 1*/
    
    eststo clear
    
    foreach var of varlist y1 y2 y3{
    eststo: areg `var' i.treat##i.after x1 x2 x3, absorb(x4) cluster(cluster)
    estadd local fe1 "Yes"
    estadd local fe2 "Yes"
    estadd local control "Yes"
    }
    
    esttab est1 est2 est3 using "$out\table.tex", ///
          drop (x1 x2 x3) ///
          prehead ("\begin{table}[htbp]\centering \\ \def\sym#1{\ifmode^{#1}\else\(^{#1}\)\fi} \\ \caption{title} \\ \begin{tabular}{l*{3}{c}} \hline\hline") ///
          posthead ("\hline \\ \multicolumn{3}{c}{\textbf{Panel A}} \\\\[-1ex]") ///
          fragment ///
          mtitles ("y1" "y2" "y3") stats (r2 N fe1 fe2 control, labels(R-squared "observations" "FE1" "FE2" "Control variables")) b(%8.3f) se(%8.3f)
          /*replace*/
          eststo clear
          
    
    /*panel 2*/
    
    eststo clear
    foreach var of varlist y1 y2 y3{
        eststo: areg `var' i.treat2##i.after x1 x2 x3, absorb(x4) cluster(cluster)
    estadd local fe1 "Yes"
    estadd local fe2 "Yes"
    estadd local control "Yes"
    }
    
    esttab est1 est2 est3 using "$out\table.tex" ///
          drop (x1 x2 x3) ///
          posthead("\hline \\ \multicolumn{3}{c}{\textbf{Panel B}} \\\\[-1ex]") ///
          fragment ///
          append ///
          r2 b(%8.3f) se(%8.3f) stats(r2 N fe1 fe2 control, labels(R-squared "observations" "FE1" "FE2" "Control variables")) nomtitle nonumbers
          
          
    /*panel 3*/
    
    eststo clear
    foreach var of varlist y1 y2 y3{
        eststo: areg `var' i.treat3##i.after x1 x2 x3, absorb(x4) cluster(cluster)
    estadd local fe1 "Yes"
    estadd local fe2 "Yes"
    estadd local control "Yes"
    }
    
    esttab est1 est2 est3 using "$out\table.tex" ///
          drop (x1 x2 x3)
          posthead("\hline \\ \multicolumn{3}{c}{\textbf{Panel C: title}} \\\\[-1ex]") ///
          fragment ///
          append ///
          r2 b(%8.3f) se(%8.3f) stats(r2 N fe1 fe2 control, labels(R-squared "observations" "FE1" "FE2" "Control variables")) nomtitle nonumbers ///
          prefoot ("\hline") ///
          postfoot ("\hline\hline \multicolumn{6}{l}{\footnotesize Standard errors in parentheses}\\\multicolumn{2}{l}{footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***}\(p<0.001\)}\\ \end{tabular}\\ \end{table}")
    The code works fine till panel 3, at which point while trying to export the output to "$out\table.tex", I get an error

    Code:
    file C:\Users\....\table.tex already exists
    r(602);
    I'm not quite sure why this is happening, as I append the results in panel 3 to the earlier results. Moreover, the panel 2 results are also appended in same way to panel 1 results but it doesn't get flagged as error then.

    Any help would be appreciated, thanks!

  • #2
    In Panel 3, there seems to be a line break missing. Try changing this line
    Code:
    drop (x1 x2 x3)
    to
    Code:
    drop (x1 x2 x3) ///
    .

    Comment


    • #3
      Originally posted by Rafael Copat View Post
      In Panel 3, there seems to be a line break missing. Try changing this line
      Code:
      drop (x1 x2 x3)
      to
      Code:
      drop (x1 x2 x3) ///
      .
      wow thanks! finally worked! there were also a bunch of missed commas

      Comment


      • #4
        I personally hate having to put /// at the end of every line in a long command. Like me, you might prefer to change the delimiter. See
        Code:
        help #delimit

        Comment

        Working...
        X