Announcement

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

  • How to add the mean of outcome variable to esttab output after using sdid

    I am trying to add the information about the mean of the outcome variable after using sdid, so I use
    Code:
    estadd ysumm
    to do so. But it seems like sdid did not store ysumm after iteration. So I wonder how can I add the output mean in esttab. Also is there a way to add the Y mean in the graph? Following is the store list return after I run sdid:

    Code:
    scalars:
                e(N_clust) =  49
                   e(reps) =  50
                    e(ATT) =  -.0819336
                     e(se) =  .0105743
                      e(N) =  2352
    
    macros:
                    e(cmd) : "sdid"
                  e(title) : "Synthetic Difference-in-Differences"
                    e(vce) : "bootstrap"
                 e(depvar) : "r_wp"
               e(clustvar) : "state"
                e(cmdline) : "sdid crime_rate state date treat, vce(bootstrap) covariates(pop_1000 r_black r_notwhite unemploymentrate income_per_capita r_HS r_college lgdp tdate tst.."
             e(properties) : "b V"
    
    matrices:
                      e(b) :  1 x 1
                      e(V) :  1 x 1
             e(difference) :  48 x 2
                 e(series) :  48 x 3
                   e(beta) :  11 x 1
               e(adoption) :  1 x 1
                  e(omega) :  48 x 2
                 e(lambda) :  49 x 2
                    e(tau) :  1 x 3
    And here is an example similar to what I am using:

    Code:
    eststo sdid1: sdid crime_rate state date treat, vce(bootstrap) covariates(pop_1000 r_black r_notwhite unemploymentrate income_per_capita r_HS r_college lgdp tdate tstate, optimized) seed(1234) graph g1on 
    
    esttab sdid1  using "tables/Crime rate.tex", title("Crime rate) starlevel ("*" 0.10 "**" 0.05 "***" 0.01) b(%-9.3f) se(%-9.3f) mtitles( "Drug Crime"  ) replace
    Code:
    Crime Rate
    ----------------------------
                          (1)   
                   Crime Rate   
    ----------------------------
    treat              -0.082***
                      (0.011)   
    ----------------------------
    N                    2352   
    ----------------------------
    Standard errors in parentheses
    * p<0.10, ** p<0.05, *** p<0.01
    but I want:
    Code:
    Crime Rate
    -----------------------------------------------------
                                        (1)   
                                    Crime Rate   
    ------------------------------------------------------
    treat                             -0.082***
                                      (0.011)   
    Crime rate average                  ...
                                       (...)
    ------------------------------------------------------
    N                                 2352   
    ------------------------------------------------------
    Standard errors in parentheses
    * p<0.10, ** p<0.05, *** p<0.01

  • #2
    Hi Wenhan,

    Not sure about the graph, but you should be able to adapt the following code to add the mean of the outcome to your table:

    Code:
    clear
    sysuse auto
    
    eststo m1: reg price mpg
    qui summ price
    local mu : di %5.2f r(mean)
    estadd local mu `mu'
    
    esttab m1, scalars("mu Mean")

    Comment


    • #3
      estout is from SSC, as you are asked to explain (FAQ Advice #12). Two issues:

      i. You are not saving the statistic with the regression estimates.
      ii. Statistics in esttab appear below the vertical line separating coefficients. What you are saving is a statistic.

      Code:
      eststo sdid1: sdid crime_rate state date treat, vce(bootstrap) covariates(pop_1000 r_black r_notwhite unemploymentrate income_per_capita r_HS r_college lgdp tdate tstate, optimized) seed(1234) graph g1on 
      
      sum crime_rate if e(sample)
      estadd scalar ysumm= r(mean): sdid1
      esttab sdid1 using "tables/Crime rate.tex", title("Crime rate) stats(N ysumm) starlevel ("*" 0.10 "**" 0.05 "***" 0.01) b(%-9.3f) se(%-9.3f) mtitles( "Drug Crime" ) replace
      You can label the statistics as you wish.

      Code:
      help esttab

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        estout is from SSC, as you are asked to explain (FAQ Advice #12). Two issues:

        i. You are not saving the statistic with the regression estimates.
        ii. Statistics in esttab appear below the vertical line separating coefficients. What you are saving is a statistic.

        Code:
        eststo sdid1: sdid crime_rate state date treat, vce(bootstrap) covariates(pop_1000 r_black r_notwhite unemploymentrate income_per_capita r_HS r_college lgdp tdate tstate, optimized) seed(1234) graph g1on
        
        sum crime_rate if e(sample)
        estadd scalar ysumm= r(mean): sdid1
        esttab sdid1 using "tables/Crime rate.tex", title("Crime rate) stats(N ysumm) starlevel ("*" 0.10 "**" 0.05 "***" 0.01) b(%-9.3f) se(%-9.3f) mtitles( "Drug Crime" ) replace
        You can label the statistics as you wish.

        Code:
        help esttab
        Hello Andrew,

        Thank you for the quick and accurate respond, may I ask if I want to add this statistic into my graph, should I need to list the statisitc first using
        Code:
        ereturn list
        and then use yline?

        Comment


        • #5
          You could hold it in a local macro or refer to the result stored by summarize if not overwritten, then use the -text()- option to place it in the graph.

          Code:
          webuse grunfeld, clear
          sum mvalue if company==1
          line mvalue year if company==1, xtitle("") text(5500 1945 "{it: Mean} = `:di %3.2f `r(mean)'' ")
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	43.0 KB
ID:	1751639

          Last edited by Andrew Musau; 29 Apr 2024, 09:50.

          Comment


          • #6
            Originally posted by Andrew Musau View Post
            estout is from SSC, as you are asked to explain (FAQ Advice #12). Two issues:

            i. You are not saving the statistic with the regression estimates.
            ii. Statistics in esttab appear below the vertical line separating coefficients. What you are saving is a statistic.

            Code:
            eststo sdid1: sdid crime_rate state date treat, vce(bootstrap) covariates(pop_1000 r_black r_notwhite unemploymentrate income_per_capita r_HS r_college lgdp tdate tstate, optimized) seed(1234) graph g1on
            
            sum crime_rate if e(sample)
            estadd scalar ysumm= r(mean): sdid1
            esttab sdid1 using "tables/Crime rate.tex", title("Crime rate) stats(N ysumm) starlevel ("*" 0.10 "**" 0.05 "***" 0.01) b(%-9.3f) se(%-9.3f) mtitles( "Drug Crime" ) replace
            You can label the statistics as you wish.

            Code:
            help esttab
            Hello Andrew,

            I just realized that the result the "sdid" store did not have "e(sample)", should I just use
            Code:
             sum crime_rate  
            
            estadd scalar ysumm= r(mean): sdid1
            Since if I include "e(sample)", nothing to return

            Comment


            • #7
              This will work only if

              Code:
              count if !missing(crime_rate)
              assert r(N)==e(N)
              holds. Otherwise, the mean value will be off.

              Comment


              • #8
                Originally posted by Andrew Musau View Post
                This will work only if

                Code:
                count if !missing(crime_rate)
                assert r(N)==e(N)
                holds. Otherwise, the mean value will be off.
                So what if I use something like this:
                Code:
                 
                  sum crime_rate if !missing(crime_rate)
                I mean now if I only calcualte those who where used in the analysis

                Comment


                • #9
                  That won't necessarily work because the estimation sample depends on missing values in the RHS variables as well. See the definition of listwise deletion. So the assert condition in #6 must first hold for

                  sum crime_rate if !missing(crime_rate)
                  to be valid.

                  Comment


                  • #10
                    Originally posted by Andrew Musau View Post
                    That won't necessarily work because the estimation sample depends on missing values in the RHS variables as well. See the definition of listwise deletion. So the assert condition in #6 must first hold for



                    to be valid.
                    I see thank you for the explanation, luckly the variables I am using for LHS and RHS does not have missing value.

                    Comment

                    Working...
                    X