Announcement

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

  • Putexcel levels of interaction term

    Dear Stata users,

    I'm using -putexcel- to export the results of a regression model into an Excel spreadsheet:

    svy, subpop(sample): reg pulse_oz i.agecat##i.wave kcal
    margins i.agecat##i.wave, subpop (sample)
    matrix M=r(table)'
    putexcel B2=matrix (M)

    However, I'm having some trouble with exporting the levels of i.agecat##i.wave into column A. Since i.agecat has 2 levels and i.wave has 2 levels, column A should look like this:

    11
    12
    21
    22

    ...but I can't seem to figure out how to do that. I've reviewed the documentation for stored results as well as this forum but I haven't been able to identify a solution. I'd be grateful for any suggestions. Thank you.

  • #2
    Your post does not specify the issue that you are facing. I would recommend that you provide a reproducible example illustrating how the output differs from what you want.

    Comment


    • #3
      Thank you for your reply. The issue that I am facing is that I cannot identify the command I need to produce any output. I would like to export the levels of a 2x2 interaction term to an Excel column after I run a regression model. I've provided the code I am using to do that as well as an example of what it should look like.

      Comment


      • #4
        You need a single # in the margins command.

        Code:
        webuse lbw, clear
        regress bwt c.age##c.age i.smoke##i.ht
        margins i.smoke#i.ht
        putexcel set myfile, replace
        putexcel A1= matrix(r(table)'), rownames
        Res.:

        Code:
        . margins i.smoke#i.ht
        
        Predictive margins                                         Number of obs = 189
        Model VCE: OLS
        
        Expression: Linear prediction, predict()
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |     Margin   std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
            smoke#ht |
        Nonsmoker#0  |   3080.456   67.85062    45.40   0.000     2946.586    3214.326
        Nonsmoker#1  |   2577.932    267.252     9.65   0.000     2050.641    3105.223
           Smoker#0  |   2797.044    84.8533    32.96   0.000     2629.628    2964.461
           Smoker#1  |   2547.842   315.0079     8.09   0.000     1926.328    3169.356
        ------------------------------------------------------------------------------
        Res.:

        Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	49.3 KB
ID:	1736218

        Comment


        • #5
          Hi Andrew, that worked! Thank you so much for your help with this.

          Comment

          Working...
          X