Announcement

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

  • outreg2 and didregress

    Hello,
    I'm using the didregress command of STATA, and I'm saving the output into a Excel file using outreg2.
    But outreg2 saves two columns: one with just the estimate of the ATET, and the other column with everything else (constant, controls, etc.)
    How can I have everything in one column?
    Best

  • #2
    Dear Giuseppe,

    I would try using the new -etable-. Here is an example to get your table to Excel.

    Code:
    webuse hospdd, clear 
    
    didregress (satis) (procedure), group(hospital) time(month)
    etable, export(mytable.xlsx, replace as(xlsx))

    Comment


    • #3
      Thanks.

      How can I have these models share the same rows?

      They are put on top of one another.

      I would like them side-by-side.

      Code:
      webuse hospdd, clear
      
      didregress (satis) (procedure), group(hospital) time(month)
      estimates store model1
      
      regress satis i.hospital i.month i.procedure, cluster(hospital)
      estimates store model2
      
      etable, estimates(model1 model2) export(mytable.xlsx, replace as(xlsx))

      Comment


      • #4
        Another question, on top of the previous one: how can I tell etable that it should retain only the intercept and the treatment effect in the didregress output?

        Comment


        • #5
          Hi Giuseppe,

          I do not quite understand what you want to be side by side, given that there are different regressors and equations that you could potentially align. That being said, -etable- calls the new table commands and -collect-. So, you can get to what you want using those tools. I would try the -eqrecode()- option of -etable-. Here is a thread that you might find to be useful.

          https://www.statalist.org/forums/for...date-for-v17-0

          Comment


          • #6
            Thanks.

            I'm almost there.

            This is the code I have so far.

            Now, how can I have the two treatment effects side-by-side?

            The treatment effect of didregress is in its own row.

            Code:
            clear all
            
            webuse hospdd, clear
            
            quietly didregress (satis) (procedure), group(hospital) time(month)
            quietly estimates store model1
            
            // alternative 2: areg
            quietly areg satis i.procedure i.month, absorb(hospital) vce(cluster hospital)
            quietly estimates store model2
            
            etable, estimates(model1 model2) eqrecode(ATET=satis Controls=satis)
            Last edited by Giuseppe Polito; 13 May 2022, 02:14.

            Comment


            • #7
              Hi Giuseppe,

              Now, I understand how you want to align your table. The key here is to use -collect remap- to align the coefficients of 1.procedure and r1vs0.procedure.

              Here is an alternative:

              Code:
              clear all 
              
              webuse hospdd, clear
              
              didregress (satis) (procedure), group(hospital) time(month)
              estimates store model1
              
              regress satis i.hospital i.month i.procedure, cluster(hospital)
              estimates store model2
              
              etable, estimates(model1 model2)                               ///
                              export(mytable.xlsx, replace as(xlsx))         ///
                              eqrecode(ATET=xb Controls=xb satis=xb)
              
              * list the colname to see r1vs0.procedure and 1.procedure
              collect levelsof colname
              
              * remap 1.procedure to be in the same row of r1vs0.procedure
              collect remap colname[1.procedure] = colname[r1vs0.procedure]
              
              collect preview
              
              collect export mytable.xlsx, replace

              Comment


              • #8
                Thank you very much!

                Here is the code I have so far (I just substituted your `regress` with `areg`).

                Last question: how can I get rid of the `month` variable in the output?

                Code:
                // alternative 1: xtreg
                //quietly xtreg satis i.procedure, i(month) fe vce(cluster hospital)
                
                clear all
                
                webuse hospdd, clear
                
                didregress (satis) (procedure), group(hospital) time(month)
                estimates store model1
                
                areg satis i.month i.procedure, absorb(hospital) vce(cluster hospital)
                estimates store model2
                
                etable, estimates(model1 model2)                               ///
                                export(mytable.xlsx, replace as(xlsx))         ///
                                eqrecode(ATET=xb Controls=xb satis=xb)
                
                * list the colname to see r1vs0.procedure and 1.procedure
                collect levelsof colname
                
                * remap 1.procedure to be in the same row of r1vs0.procedure
                collect remap colname[1.procedure] = colname[r1vs0.procedure]
                
                collect preview
                
                collect export mytable.xlsx, replace
                Best regards

                Comment


                • #9
                  I think this is what you want

                  Code:
                  // alternative 1: xtreg
                  //quietly xtreg satis i.procedure, i(month) fe vce(cluster hospital)
                  
                  clear all
                  
                  webuse hospdd, clear
                  
                  didregress (satis) (procedure), group(hospital) time(month)
                  estimates store model1
                  
                  areg satis i.month i.procedure, absorb(hospital) vce(cluster hospital)
                  estimates store model2
                  
                  etable, estimates(model1 model2)                               ///
                                  export(mytable.xlsx, replace as(xlsx))         ///
                                  eqrecode(ATET=xb Controls=xb satis=xb)
                  
                  * list the colname to see r1vs0.procedure and 1.procedure
                  collect levelsof colname
                  
                  * remap 1.procedure to be in the same row of r1vs0.procedure
                  collect remap colname[1.procedure] = colname[r1vs0.procedure]
                  
                  * Look at the current layout and then modify 
                  collect layout 
                  
                  * Change layout (note colname[] was empty now I specified what I wanted)
                  
                  collect layout                                                        ///
                      (coleq#colname[r1vs0.procedure]#result[_r_b _r_se] result[N])    ///
                      (etable_depvar#stars[value])
                      
                  collect preview
                  
                  collect export mytable.xlsx, replace

                  Comment


                  • #10
                    Thanks! That would work!

                    Best regards.

                    Comment


                    • #11
                      Hi,

                      sorry another question: how can I add rows to the output?

                      I would like to add a row "Year fixed effects" with "Yes" in all three columns.

                      Also, how Ican customize column headers?

                      Here is the code I have so far:

                      Code:
                      clear all
                      
                      webuse hospdd, clear
                      
                      didregress (satis) (procedure), group(hospital) time(month)
                      estimates store model1
                      
                      areg satis i.(procedure month), absorb(hospital) vce(cluster hospital)
                      estimates store model2
                      
                      xtreg satis i.(procedure month), i(hospital) fe vce(cluster hospital)
                      estimates store model3
                      
                      regress satis i.(procedure month hospital), vce(cluster hospital)
                      estimates store model4
                      
                      etable, estimates(model1 model2 model3 model4)                               ///
                                      export(mytable.xlsx, replace as(xlsx))         ///
                                      eqrecode(ATET=xb Controls=xb satis=xb)         ///
                              column(title)
                      
                      * list the colname to see r1vs0.procedure and 1.procedure
                      collect levelsof colname
                      
                      * remap 1.procedure to be in the same row of r1vs0.procedure
                      collect remap colname[1.procedure] = colname[r1vs0.procedure]
                      
                      * Look at the current layout and then modify
                      collect layout
                      
                      * Change layout (note colname[] was empty now I specified what I wanted)
                      
                      collect layout                                                        ///
                          (coleq#colname[r1vs0.procedure _cons]#result[_r_b _r_se] result[N])    ///
                          (etable_depvar#stars[value])
                          
                      collect preview
                      
                      collect export mytable.xlsx, replace

                      Comment


                      • #12
                        Hi Giuseppe,

                        Below is code to add a column manually. Note, I only placed "Yes" in one column to illustrate but you can place if for any column. In other words, you could modify the index in -collect get..., tags(etable_depvar[index]).

                        Code:
                        clear all
                        
                        webuse hospdd, clear
                        
                        didregress (satis) (procedure), group(hospital) time(month)
                        estimates store model1
                        
                        areg satis i.(procedure month), absorb(hospital) vce(cluster hospital)
                        estimates store model2
                        
                        xtreg satis i.(procedure month), i(hospital) ///
                        fe vce(cluster hospital)
                        estimates store model3
                        
                        regress satis i.(procedure month hospital), vce(cluster hospital)
                        estimates store model4
                        
                        etable, estimates(model1 model2 model3 model4)                 ///
                                        export(mytable.xlsx, replace as(xlsx))         ///
                                        eqrecode(ATET=xb Controls=xb satis=xb)         ///
                                column(title)
                                
                        collect remap colname[1.procedure] = colname[r1vs0.procedure]
                        
                        * manually get row of "Yes fixed effects" for -xtreg-
                        collect levelsof etable_depvar
                        
                        collect get has_fe = "Yes", tags(etable_depvar[3])
                        
                        * modify its label
                        collect label levels result has_fe "Fixed effects", modify
                        
                        * list the current labels for column headers
                        collect label list etable_depvar
                        
                        * re-label the column headers and use them in the layout
                        collect label levels etable_depvar  ///
                                 1 "DID" 2 "Absorb" 3 "Within" 4 "Dummy", modify
                        
                        collect style header etable_depvar, level(label)
                        
                        * final table layout
                        collect layout                                                               ///
                          (coleq#colname[r1vs0.procedure _cons]#result[_r_b _r_se] result[has_fe N]) ///
                          (etable_depvar#stars[value])

                        Comment


                        • #13
                          Hi,

                          what do you mean by "manually get row of "Yes fixed effects" for -xtreg-"?

                          With:
                          Code:
                          collect levelsof etable_depvar
                          you are getting the *column* in which to put it, not the *row*, right?

                          EDIT: sorry, I see you call "columns" what I call "rows". It's just a different notation.
                          Last edited by Giuseppe Polito; 28 Jun 2022, 04:44.

                          Comment

                          Working...
                          X