Announcement

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

  • how to export the (direct, indirect and total) impact after spxtregress to Word

    I can use the command estat impact to get the direct, indirect and total impact after I run a spatial regression using the command spxtregress. However, I don't know how to export this direct, indirect and total impact table to a doc file of Microsoft word. I've tried the eststo and esttab, but can only get the regression result table before I use estate impact, but what I want is the calculated impacts. Any suggestions?

    Sincerely,
    Ningning

  • #2
    The specific problem is as follows.
    I use
    Code:
    spxtregress mean_winter TOTPOP CTPOP LAREA TOTGREEN PKGREEN GREENRATE GRPPC GRPPRI GRPSEC PTFC FTFC WSTW SEMS BUSVOL TOTELEC INDELEC RESDELEC LPG GAS, fe dvarlag(M) errorlag(M) ivarlag(M:TOTPOP CTPOP LAREA TOTGREEN PKGREEN GREENRATE GRPPC GRPPRI GRPSEC PTFC FTFC WSTW SEMS BUSVOL TOTELEC INDELEC RESDELEC LPG GAS)
    and get
    Click image for larger version

Name:	spxtregress.png
Views:	2
Size:	74.6 KB
ID:	1640674


    Then I use
    Code:
    estat impact
    and get
    Click image for larger version

Name:	2021-12-13 11.50.03.png
Views:	1
Size:	65.5 KB
ID:	1640675

    Click image for larger version

Name:	2021-12-13 11.50.26.png
Views:	1
Size:	82.8 KB
ID:	1640676



    But when I use
    Code:
    esttab
    I get the following

    Click image for larger version

Name:	2021-12-13 11.55.07.png
Views:	1
Size:	29.8 KB
ID:	1640678


    However, the results that I really want to export to Word (doc.file) is the direct, indirect and total (average) impacts of the spxtregress. Any solutions would be more than appreciated.
    Attached Files

    Comment


    • #3
      estout is from the Stata Journal/ SSC (FAQ Advice #12). esttab handles whatever is in e(), but the matrices holding your results are stored in r(). See

      Code:
      return list
      after estat impact. You certainly can get the default esttab presentation with some work, by placing the matrices in e(b) and e(V). Below, I put them in e(b1) and e(V1) which will allow you to output coefficients and variances with no frills. If you are interested in stars, standard errors or z-statistics, see the sentence that precedes the previous.


      Code:
      copy https://www.stata-press.com/data/r16/homicide1990.dta .
      copy https://www.stata-press.com/data/r16/homicide1990_shp.dta .
      use homicide1990
      spset
      spmatrix create contiguity W
      spregress hrate ln_population ln_pdensity gini, gs2sls dvarlag(W)
      estat impact
      estadd matrix b1= r(b)
      estadd matrix V1=r(V)
      esttab, cells("b1 V1") collab(Coefficient Variance) nonumb nomtitle

      Res.:

      Code:
      . esttab, cells("b1 V1") collab(Coefficient Variance) nonumb nomtitle
      
      --------------------------------------
                    Coefficient     Variance
      --------------------------------------
      direct                                
      ln_populat~n     .1971473     .0713704
      ln_pdensity      1.068497    -.0518257
      gini              77.6676     .1109043
      --------------------------------------
      indirect                              
      ln_populat~n     .0471186     .0155732
      ln_pdensity      .2553728    -.0204319
      gini             18.56271    -.5583047
      --------------------------------------
      total                                 
      ln_populat~n     .2442659     .0869436
      ln_pdensity      1.323869    -.0722575
      gini             96.23031    -.4474003
      --------------------------------------
      N                    1412             
      --------------------------------------

      Comment


      • #4
        Thanks very much for your reply, Andrew.

        Yes, you are right, how can I proceed further to get z-statistics and label coefficients with stars which indicate statistical significance (for the direct, indirect and total effects as well)? Shall I look up help estout or esttab in the Stata documentation?

        Many thanks,
        Ningning

        Comment


        • #5
          The work in putting the matrices in e(b) and e(V) lies in finding a multiple equations estimator and replacing its results. Such an estimator is sureg. Here, the number of parameters in an equation matters: I specify a loop where you can specify this number. In my example, there are three. Otherwise this should work as a general solution for outputting estat impact results using esttab. Replacement is done by the erepost command from SSC.

          Code:
          copy https://www.stata-press.com/data/r16/homicide1990.dta .
          copy https://www.stata-press.com/data/r16/homicide1990_shp.dta .
          use homicide1990
          spset
          spmatrix create contiguity W
          spregress hrate ln_population ln_pdensity gini, gs2sls dvarlag(W)
          estat impact
          mat b= r(b)
          mat V= r(V)
          foreach eq in direct indirect total{
              gen  `eq'= runiformint(1,10)
          }
          gen zero=0
          local vars
          forval i=1/3{
              local vars "`vars' zero"
          }
          sureg (direct `vars', nocons)(indirect `vars', nocons) (total `vars', nocons)
          erepost b= b, rename
          erepost V=V, rename
          esttab, mlabel(none) se unstack nonumbers

          Res.:

          Code:
          . esttab, mlabel(none) se unstack nonumbers
          
          ------------------------------------------------------------
                             direct        indirect           total   
          ------------------------------------------------------------
          ln_populat~n        0.197          0.0471           0.244   
                            (0.267)        (0.0600)         (0.326)   
          
          ln_pdensity         1.068***        0.255*          1.324***
                            (0.233)         (0.113)         (0.324)   
          
          gini                77.67***        18.56**         96.23***
                            (5.262)         (5.812)         (7.410)   
          ------------------------------------------------------------
          N                    1412                                   
          ------------------------------------------------------------
          Standard errors in parentheses
          * p<0.05, ** p<0.01, *** p<0.001
          Last edited by Andrew Musau; 14 Dec 2021, 05:52.

          Comment


          • #6
            Hi Andrews,
            I have the same question as Ningning Sun.
            I tried your code (also just copied your example) and after the sureg command it always gives me an error message 'there are at least as many constraints as parametersr(498);'.
            Do you have any suggestions for me in this regard?
            Thank you.

            Comment


            • #7
              I also tried the code provided by Andrews, but it seems to not work anymore. Is there any other option on how to export those results (direct, indirect and total effects)? Thank you

              Comment

              Working...
              X