Announcement

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

  • Rename estimated coefficients

    Hi,

    Im trying to make a table with three different models but the estimated coefficient in CSDID is not named the same as in TWFE and in the Stacked model so my tables looks like this:
    TWFE Stacked reg CSDID
    Post 123 123
    ATT 123
    How can I rename "ATT" to "post" for my estimated coefficients? I have tried estout using CSDID, rename(ATT post) and esttab, rename(ATT post) without success.



    I'm currently using est save to save my estimates then est store and est out(seen below) to use them in my table. Here is a sample of the beginning of my tables:


    estout tsno5 ssno5 csno5 tsc5 ssc5 csc5 using "twfe.tex", replace ///
    style(tex) ///
    cells(b(fmt(a3) star) se(fmt(a3) par)) ///
    starl( * 0.10 ** 0.05 *** 0.010) ///
    keep(post_ev ATT) ///
    varlabels(post_ev "Post" ALL "Post") ///
    mlabels("TWFE" "Stacked" "CS" "TWFE(no cov)" "Stacked(no cov)" "CS(no cov)" ) collabels(none) ///
    substitute(_ \_ # \#) ///
    prehead( \footnotesize \centering `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' ///
    "\begin{threeparttable} \begin{tabular}{l*{@E}{c}} \toprule \toprule" ///
    "\caption{Estimates for all methods & region: all & km:5}" ///
    "& \multicolumn{6}{c}{\textsc{A. Static model}} \") ///
    posthead(\cmidrule(lr){2-7} \\) ///
    prefoot() ///
    postfoot()

    .
    .
    .
    .

    Many thanks!

  • #2
    In esttab, I think the name change option is coef(ATT post)

    Comment


    • #3
      Hi George!

      the command does change the name but only for display, it doesn't save the name. Maybe esttab is not the right function? but I cannot find any rename option for est save or est store?


      Thank you

      Comment


      • #4
        open csdid.ado. look at line 740. Change that to "Post". Run it the ado. Then run the model to see if that does it.

        Comment


        • #5
          Look at how one can rename a coefficient using erepost from SSC in https://www.statalist.org/forums/for...em-to-tex-file. Editing the ado-file will work, but it seems overkill.

          Comment


          • #6
            I encountered the same issue with csdid—the aggregated coefficient is always named “ATT,” which prevented it from aligning with my TWFE results in the esttab table.
            The following approach resolved it:

            // Rename the ATT coefficient using nlcom
            nlcom <desired_name> = _b[ATT]

            // Store the renamed estimates
            est store cs_result


            By using nlcom to rename the coefficient and then storing that result, I could display the TWFE result and the csdid result on the same row.
            I hope this helps anyone else facing the same problem.
            Last edited by KOBAYASHI Ryuki; 07 Jul 2025, 00:02.

            Comment


            • #7
              A remark on the useful advice in #6:

              Originally posted by KOBAYASHI Ryuki View Post

              // Rename the ATT coefficient using nlcom
              nlcom <desired_name> = _b[ATT]

              // Store the renamed estimates
              est store cs_result
              This syntax does not appear to be correct for nlcom. From the documentation, the syntax should be:


              Nonlinear combination of parameters -- one expression

              nlcom [name:]exp [, options]
              So one would need:

              Code:
              nlcom <desired_name> : _b[ATT]

              Example:

              Code:
              sysuse auto, clear
              regress mpg weight displacement
              *SUGGESTED
              nlcom myname= _b[weight]
              
              *CORRECTED
              nlcom myname: _b[weight]
              Res.:

              Code:
              . regress mpg weight displacement
              
                    Source |       SS           df       MS      Number of obs   =        74
              -------------+----------------------------------   F(2, 71)        =     66.79
                     Model |  1595.40969         2  797.704846   Prob > F        =    0.0000
                  Residual |  848.049768        71  11.9443629   R-squared       =    0.6529
              -------------+----------------------------------   Adj R-squared   =    0.6432
                     Total |  2443.45946        73  33.4720474   Root MSE        =    3.4561
              
              ------------------------------------------------------------------------------
                       mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                    weight |  -.0065671   .0011662    -5.63   0.000    -.0088925   -.0042417
              displacement |   .0052808   .0098696     0.54   0.594    -.0143986    .0249602
                     _cons |   40.08452    2.02011    19.84   0.000     36.05654    44.11251
              ------------------------------------------------------------------------------
              
              . 
              . *SUGGESTED
              
              . 
              . nlcom myname= _b[weight]
              
              "=" not allowed in expression
              r(198);
              
              . 
              . 
              . 
              . *CORRECTED
              
              . 
              . nlcom myname: _b[weight]
              
                    myname: _b[weight]
              
              ------------------------------------------------------------------------------
                       mpg | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                    myname |  -.0065671   .0011662    -5.63   0.000    -.0088529   -.0042813
              ------------------------------------------------------------------------------
              
              .

              Comment


              • #8
                Dear Mr. Musau,

                Thank you very much for pointing out the syntax mistake. I had a typo. The code you provided is correct.

                Comment


                • #9
                  Masau: could you suggest how to use this after csdid? If I use
                  nlcom <desired_name> : _b[ATT] after csdid, I get the error "ATT not found".

                  Comment


                  • #10
                    You need to post the estat results first.

                    Code:
                    use https://friosavila.github.io/playingwithstata/drdid/mpdta.dta, clear
                    csdid lemp lpop , ivar(countyreal) time(year) gvar(first_treat) method(dripw)
                    estat simple, post
                    nlcom Post: _b[ATT], post
                    esttab
                    Res.:

                    Code:
                    . 
                    . estat simple, post
                    Average Treatment Effect on Treated
                    ------------------------------------------------------------------------------
                                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
                    -------------+----------------------------------------------------------------
                             ATT |  -.0417518   .0115028    -3.63   0.000    -.0642969   -.0192066
                    ------------------------------------------------------------------------------
                    
                    . 
                    . nlcom Post: _b[ATT], post
                    
                            Post: _b[ATT]
                    
                    ------------------------------------------------------------------------------
                                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
                    -------------+----------------------------------------------------------------
                            Post |  -.0417518   .0115028    -3.63   0.000    -.0642969   -.0192066
                    ------------------------------------------------------------------------------
                    
                    . 
                    . esttab
                    
                    ----------------------------
                                          (1)   
                                                
                    ----------------------------
                    Post              -0.0418***
                                      (-3.63)   
                    ----------------------------
                    N                           
                    ----------------------------
                    t statistics in parentheses
                    * p<0.05, ** p<0.01, *** p<0.001
                    
                    .

                    Comment

                    Working...
                    X