Announcement

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

  • how to drop variables from the dummy interaction variable with zero values using outreg2 command?

    Dear Stata Experts,

    I encountered a simple command to export my table using outreg but I am lost on how to specify in the dummy variable I need to drop.

    Let me show you the codes and stata result.

    [CODE]

    xtreg InpatientNo i.Agegroup_new i.Country_new Agegroup_new##Country_new, re robust

    Random-effects GLS regression Number of obs = 19,352
    Group variable: panelid Number of groups = 7,068

    R-squared: Obs per group:
    Within = 0.0000 min = 1
    Between = 0.0192 avg = 2.7
    Overall = 0.0175 max = 3

    Wald chi2(7) = 354.73
    corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000

    (Std. err. adjusted for 7,068 clusters in panelid)
    ------------------------------------------------------------------------------------------
    | Robust
    InpatientNo | Coefficient std. err. z P>|z| [95% conf. interval]
    -------------------------+----------------------------------------------------------------
    Agegroup_new |
    15-39 | 102.9816 52.41481 1.96 0.049 .2504866 205.7128
    40-69 | 706.6887 78.92718 8.95 0.000 551.9943 861.3832
    70+ | 302.6225 48.34639 6.26 0.000 207.8653 397.3797

    Country_new |
    Switzerland | 81.39452 67.38679 1.21 0.227 -50.68117 213.4702

    Agegroup_new#Country_new |
    15-39#Switzerland | 29.37796 91.83564 0.32 0.749 -150.6166 209.3725
    40-69#Switzerland | -354.0323 107.3944 -3.30 0.001 -564.5213 -143.5432
    70+#Switzerland | 41.87351 87.90335 0.48 0.634 -130.4139 214.1609

    _cons | 62.89575 13.22812 4.75 0.000 36.96911 88.82239
    -------------------------+----------------------------------------------------------------
    sigma_u | 1410.2979
    sigma_e | 312.15199
    rho | .95329762 (fraction of variance due to u_i)
    ------------------------------------------------------------------------------------------

    [CODE]

    outreg2 using myreg.doc, title(Panel Data Regression Random Effects) drop(Agegroup_new##Country_newFinland) addstat ("Prob > chi2",e(p))

    Panel Data Regression Random Effects
    (1)
    VARIABLES InpatientNo
    2.Agegroup_new 103.0**
    (52.41)
    3.Agegroup_new 706.7***
    (78.93)
    4.Agegroup_new 302.6***
    (48.35)
    2.Country_new 81.39
    (67.39)
    1b.Agegroup_new#1b.Country_new 0
    (0)
    1b.Agegroup_new#2o.Country_new 0
    (0)
    2o.Agegroup_new#1b.Country_new 0
    (0)
    2.Agegroup_new#2.Country_new 29.38
    (91.84)
    3o.Agegroup_new#1b.Country_new 0
    (0)
    3.Agegroup_new#2.Country_new -354.0***
    (107.4)
    4o.Agegroup_new#1b.Country_new 0
    (0)
    4.Agegroup_new#2.Country_new 41.87
    (87.90)
    Constant 62.90***
    (13.23)
    Observations 19,352
    Number of panelid 7,068
    Prob > chi2 0

    Robust standard errors in parentheses
    *** p<0.01, ** p<0.05, * p<0.1



    In this case, The base country for the interaction dummy variable Agegroup_new##Country_new is Finland with 0 coefficients. The variables 1b.Agegroup_new#1b.Country_new, 1b.Agegroup_new#2o.Country_new, 2o.Agegroup_new#1b.Country_new, 3o.Agegroup_new#1b.Country_new, 4o.Agegroup_new#1b.Country_new have to be drop using outreg2 command but I couldn`t find the right way to drop these. I also use the words shown on the table to be dropped but no effect. Can someone help me?

    Kind Regards,
    Rose
    Last edited by Rose Strebel; 14 Mar 2023, 06:58.

  • #2
    outreg2 is from SSC (FAQ Advice #12). This command is old and not updated. I have found it difficult to reference the interaction terms when using it in the past. As you need to keep some interaction terms, neither the option -keep()- nor -drop()- will work without knowing how to reference the interaction terms. As the command uses the coefficients' matrix and VCE from the estimation command, you can deal with this at the level of the estimation command by specifying exactly the interactions to keep instead of the using the double hash syntax. Here is a reproducible example:

    Code:
    webuse nhanes2.dta, clear
    reg  bpsystol i.sex##i.race  age height weight
    outreg2 using myfile, replace seeout
    Res.:
    Click image for larger version

Name:	Capture1.PNG
Views:	1
Size:	23.5 KB
ID:	1705706




    And now specifying only relevant interactions in the command:

    Code:
    webuse nhanes2.dta, clear
    reg  bpsystol i.sex i.race  2.sex#2.race 2.sex#3.race age height weight
    outreg2 using myfile, replace seeout
    Click image for larger version

Name:	Capture1.PNG
Views:	1
Size:	17.8 KB
ID:	1705707

    Last edited by Andrew Musau; 14 Mar 2023, 14:02.

    Comment


    • #3
      Wow! Thank you so much, Andrew. It worked! Thank you for saving my life with this. I wish you a great day.

      Comment

      Working...
      X