Announcement

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

  • two dummy variables interactions with specific condition

    Hello, have panel data of 171 countries from 1996-2019, and "https://www.statalist.org/forums/forum/general-stata-discussion/general/1675380-graph-for-evolution-variable-in-panel-form" is part of my data, and my baseline model is :

    Code:
    xtscc d0ltotalfertility l(0/2).pand_res_pt#(1-ae) l(0/2).pand_res_pt#non-ae l(1/1)d0ltotalfertility  i.year,fe
    which
    Code:
    pand_res_pt
    is dummy variables that get 1 in the time of recession and 0 otherwise, which is a shock in my model.

    and "ltotalfertility" is the log of fertility rate

    I wonder to see the analysis for advanced vs non-advanced with the interaction of the shock with a dummy – for total fertility rate, so first of all I generate the dummy variable "ae"=1 of an advanced economy and 0 otherwise.
    and for the non-advanced also generate the non_adv=1 if non-advanced and 0 otherwise.

    now Y=a+b1*x(1-adv) + b2*adv,

    but
    in my regression when I add the interaction term, I did :
    Code:
    xtscc d0ltotalfertility l(0/2).pand_res_pt#(1-ae) l(0/2).pand_res_pt#ae l(1/1)d0ltotalfertility  i.year,fe
    I received an error that
    1 invalid name
    r(198);

    but when I estimate in the simple regression : xtscc d0ltotalfertility l(0/2).pand_res_pt l(0/2).pand_res_pt l(1/1)d0ltotalfertility i.year if ae==1 ,fe

    I get the results:
    Code:
     xtscc d0ltotalfertility l(0/2).pand_res_pt  l(1/1)d0ltotalfertility  i.year if ae==1,fe
    
    Regression with Driscoll-Kraay standard errors   Number of obs     =       480
    Method: Fixed-effects regression                 Number of groups  =        24
    Group variable (i): ifscode                      F( 23,    19)     =      4.36
    maximum lag: 2                                   Prob > F          =    0.0009
                                                     within R-squared  =    0.2858
    
    -----------------------------------------------------------------------------------
                      |             Drisc/Kraay
    d0ltotalfertility | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    ------------------+----------------------------------------------------------------
          pand_res_pt |
                  --. |  -.0118819   .0101403    -1.17   0.256    -.0331058    .0093421
                  L1. |  -.0082734   .0045952    -1.80   0.088    -.0178913    .0013446
                  L2. |  -.0246423   .0090083    -2.74   0.013     -.043497   -.0057877
                      |
    d0ltotalfertility |
                  L1. |   .0418261   .0946173     0.44   0.663    -.1562101    .2398624
                      |
                 year |
                1996  |          0  (empty)
                1997  |          0  (omitted)
                1998  |   .0111177   .0003693    30.10   0.000     .0103447    .0118907
                1999  |   .0258679   .0010344    25.01   0.000     .0237028     .028033
                2000  |   .0422096   .0003334   126.62   0.000     .0415119    .0429074
                2001  |    .002944   .0019368     1.52   0.145    -.0011097    .0069977
                2002  |    .025964   .0017114    15.17   0.000     .0223821     .029546
                2003  |   .0301912   .0005511    54.78   0.000     .0290377    .0313447
                2004  |   .0344751    .000893    38.61   0.000     .0326061    .0363441
                2005  |   .0273988   .0011047    24.80   0.000     .0250867     .029711
                2006  |   .0459436   .0004741    96.91   0.000     .0449513    .0469359
                2007  |   .0372346    .002296    16.22   0.000     .0324291    .0420402
                2008  |   .0440433   .0015482    28.45   0.000      .040803    .0472836
                2009  |   .0220309   .0085197     2.59   0.018     .0041991    .0398628
                2010  |   .0364267   .0031583    11.53   0.000     .0298164    .0430371
                2011  |   .0287997    .006892     4.18   0.001     .0143746    .0432247
                2012  |   .0251388   .0016314    15.41   0.000     .0217242    .0285534
                2013  |  -.0046172   .0006605    -6.99   0.000    -.0059997   -.0032346
                2014  |   .0349674   .0031627    11.06   0.000     .0283479     .041587
                2015  |   .0220649    .000931    23.70   0.000     .0201162    .0240136
                2016  |   .0229065   .0003692    62.04   0.000     .0221337    .0236792
                2017  |          0  (omitted)
                2018  |          0  (omitted)
                2019  |          0  (omitted)
                      |
                _cons |   -.023716   .0001806  -131.34   0.000    -.0240939    -.023338
    -----------------------------------------------------------------------------------

    , I hope I could receive your advice and assistance so soon on how can I do the interaction in the model without generating manually before on the regression,


    many thanks in advance for your valuable time and advice.

    Best regards,

  • #2
    Caveat: I am not familiar with the -xtscc- command, which is not part of official Stata*. But I don't think that matters. The problem here is a general one relating to factor-variable notation syntax. The things that appear in an interaction term in factor-variable notation must be variables, not expressions. (1-ae) is not a variable. That's the source of your problem.

    In any case, your approach to this, even if it worked, is unnecessarily complicated. You have no need of several variables for your purpose. You just need to include the interaction with ae. So the code
    Code:
    xtscc d0ltotalfertility l(0/2).pand_res_pt#ae  l(1/1)d0ltotalfertility i.year,fe
    is all you need (assuming it is otherwise correct, which, if it works like official Stata commands do, it should be).

    *I am not claiming to be familiar with all official Stata commands.

    Comment


    • #3
      @Clyde Schechter thank you so much for your reply. I follow your advice, but I become a bit confused that in this case how can I interpret this because I could not use the (1-ae) as you mentioned to me it is not a variable. how can I see the difference between the advanced and non-advanced economies, and test them?

      I am thinking about some test like:
      y=a+b2*X*(1-D)+b3*X*D +c*D

      b2=impct when the country is not advanced; D=0


      b3=impact when the country is advanced; D=1

      y=a+b+b1*D


      bo+b1*D

      bo= is impact when D=0 when country is not advanced=b2

      bo+b1 when D=1 or advanced economies

      b0=b2; bo+b1=b3

      test bo+b1-bo=b1
      if this kind of test is correct !!



      Code:
      . xtscc d0ltotalfertility l(0/2).pand_res_pt#ae  l(1/1)d0ltotalfertility i.year,fe
      
      Regression with Driscoll-Kraay standard errors   Number of obs     =      3619
      Method: Fixed-effects regression                 Number of groups  =       182
      Group variable (i): ifscode                      F( 26,    19)     = 809493.49
      maximum lag: 2                                   Prob > F          =    0.0000
                                                       within R-squared  =    0.1630
      
      -----------------------------------------------------------------------------------
                        |             Drisc/Kraay
      d0ltotalfertility | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
      ------------------+----------------------------------------------------------------
         pand_res_pt#ae |
                   0 0  |          0  (empty)
                   0 1  |          0  (omitted)
                   1 0  |   .0026918   .0018903     1.42   0.171    -.0012646    .0066482
                   1 1  |  -.0173334   .0021461    -8.08   0.000    -.0218253   -.0128416
                        |
       L.pand_res_pt#ae |
                   0 0  |          0  (empty)
                   0 1  |          0  (omitted)
                   1 0  |  -.0081136   .0013466    -6.03   0.000    -.0109321   -.0052952
                   1 1  |   -.002655   .0047199    -0.56   0.580    -.0125339     .007224
                        |
      L2.pand_res_pt#ae |
                   0 0  |          0  (empty)
                   0 1  |          0  (omitted)
                   1 0  |  -.0008307   .0018471    -0.45   0.658    -.0046967    .0030352
                   1 1  |  -.0209225    .006022    -3.47   0.003    -.0335266   -.0083183
                        |
      d0ltotalfertility |
                    L1. |   .2662433   .0604578     4.40   0.000     .1397036     .392783
                        |
                   year |
                  1996  |          0  (empty)
                  1997  |          0  (omitted)
                  1998  |  -.0029064   .0008691    -3.34   0.003    -.0047256   -.0010873
                  1999  |   .0019696   .0008357     2.36   0.029     .0002204    .0037188
                  2000  |   .0052361    .000527     9.94   0.000     .0041331    .0063391
                  2001  |  -.0061956   .0002488   -24.90   0.000    -.0067163   -.0056749
                  2002  |   .0053032   .0008633     6.14   0.000     .0034964      .00711
                  2003  |   .0065089   .0003361    19.37   0.000     .0058055    .0072124
                  2004  |   .0093405   .0001266    73.76   0.000     .0090754    .0096056
                  2005  |   .0059029   .0001135    51.99   0.000     .0056653    .0061406
                  2006  |   .0123382   .0000582   211.94   0.000     .0122163      .01246
                  2007  |   .0122363   .0003143    38.93   0.000     .0115784    .0128943
                  2008  |    .013889   .0004023    34.52   0.000     .0130469     .014731
                  2009  |   .0058794   .0007483     7.86   0.000     .0043131    .0074457
                  2010  |   .0099586   .0004209    23.66   0.000     .0090776    .0108396
                  2011  |   .0059901   .0010854     5.52   0.000     .0037184    .0082619
                  2012  |   .0119376   .0002247    53.13   0.000     .0114674    .0124079
                  2013  |    .000501   .0002738     1.83   0.083     -.000072    .0010741
                  2014  |   .0128402   .0003622    35.45   0.000     .0120822    .0135982
                  2015  |   .0058251   .0002527    23.06   0.000     .0052962    .0063539
                  2016  |   .0071283   .0000588   121.20   0.000     .0070052    .0072514
                  2017  |          0  (omitted)
                  2018  |          0  (omitted)
                  2019  |          0  (omitted)
                        |
                  _cons |  -.0132229   .0005148   -25.69   0.000    -.0143003   -.0121454
      -----------------------------------------------------------------------------------

      Many thanks in advance for your valuable time and advice.

      Best regards,

      Comment


      • #4
        Code:
        margins pand_res_pt, dydx(ae)
        will give you the contrasts between advanced and non-advanced economies for both shock and non-shock conditions. If you want to contrast the advanced and non-advanced economies without regard to (marginal distribution over) shock, then it's
        Code:
        margins, dydx(ae)
        However, I also notice I made an important typo in the code I suggested in #2. It should be
        Code:
        xtscc d0ltotalfertility l(0/2).pand_res_pt##ae l(1/1)d0ltotalfertility i.year,fe

        Comment


        • #5
          @Clyde Schechter thanks for your reply. Sorry, if I ask because when I try to see the contrast between the advanced and non-advance I get an error. It could be becasue of the "xtscc" which I used in terms of the
          "Driscoll-Kraay standard errors", but I am not sure?

          Code:
          . xtscc d0ltotalfertility l(0/2).pand_res_pt##ae l(1/1)d0ltotalfertility i.year,fe
          
          Regression with Driscoll-Kraay standard errors   Number of obs     =      3619
          Method: Fixed-effects regression                 Number of groups  =       182
          Group variable (i): ifscode                      F( 26,    19)     = 809493.49
          maximum lag: 2                                   Prob > F          =    0.0000
                                                           within R-squared  =    0.1630
          
          -----------------------------------------------------------------------------------
                            |             Drisc/Kraay
          d0ltotalfertility | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
          ------------------+----------------------------------------------------------------
                pand_res_pt |
                         0  |          0  (empty)
                         1  |   .0026918   .0018903     1.42   0.171    -.0012646    .0066482
                            |
              L.pand_res_pt |
                         0  |          0  (empty)
                         1  |  -.0081136   .0013466    -6.03   0.000    -.0109321   -.0052952
                            |
             L2.pand_res_pt |
                         0  |          0  (empty)
                         1  |  -.0008307   .0018471    -0.45   0.658    -.0046967    .0030352
                            |
                         ae |
                         0  |          0  (empty)
                         1  |          0  (omitted)
                            |
             pand_res_pt#ae |
                       0 0  |          0  (empty)
                       0 1  |          0  (empty)
                       1 0  |          0  (empty)
                       1 1  |  -.0200252   .0030858    -6.49   0.000     -.026484   -.0135665
                            |
           L.pand_res_pt#ae |
                       0 0  |          0  (empty)
                       0 1  |          0  (empty)
                       1 0  |          0  (empty)
                       1 1  |   .0054587   .0056378     0.97   0.345    -.0063413    .0172586
                            |
          L2.pand_res_pt#ae |
                       0 0  |          0  (empty)
                       0 1  |          0  (empty)
                       1 0  |          0  (empty)
                       1 1  |  -.0200917   .0052764    -3.81   0.001    -.0311353   -.0090481
                            |
          d0ltotalfertility |
                        L1. |   .2662433   .0604578     4.40   0.000     .1397036     .392783
                            |
                       year |
                      1996  |          0  (empty)
                      1997  |          0  (omitted)
                      1998  |  -.0029064   .0008691    -3.34   0.003    -.0047256   -.0010873
                      1999  |   .0019696   .0008357     2.36   0.029     .0002204    .0037188
                      2000  |   .0052361    .000527     9.94   0.000     .0041331    .0063391
                      2001  |  -.0061956   .0002488   -24.90   0.000    -.0067163   -.0056749
                      2002  |   .0053032   .0008633     6.14   0.000     .0034964      .00711
                      2003  |   .0065089   .0003361    19.37   0.000     .0058055    .0072124
                      2004  |   .0093405   .0001266    73.76   0.000     .0090754    .0096056
                      2005  |   .0059029   .0001135    51.99   0.000     .0056653    .0061406
                      2006  |   .0123382   .0000582   211.94   0.000     .0122163      .01246
                      2007  |   .0122363   .0003143    38.93   0.000     .0115784    .0128943
                      2008  |    .013889   .0004023    34.52   0.000     .0130469     .014731
                      2009  |   .0058794   .0007483     7.86   0.000     .0043131    .0074457
                      2010  |   .0099586   .0004209    23.66   0.000     .0090776    .0108396
                      2011  |   .0059901   .0010854     5.52   0.000     .0037184    .0082619
                      2012  |   .0119376   .0002247    53.13   0.000     .0114674    .0124079
                      2013  |    .000501   .0002738     1.83   0.083     -.000072    .0010741
                      2014  |   .0128402   .0003622    35.45   0.000     .0120822    .0135982
                      2015  |   .0058251   .0002527    23.06   0.000     .0052962    .0063539
                      2016  |   .0071283   .0000588   121.20   0.000     .0070052    .0072514
                      2017  |          0  (omitted)
                      2018  |          0  (omitted)
                      2019  |          0  (omitted)
                            |
                      _cons |  -.0132229   .0005148   -25.69   0.000    -.0143003   -.0121454
          -----------------------------------------------------------------------------------
          Code:
          
          






          and my error:
          . margins pand_res_pt, dydx(ae) warning: cannot perform check for estimable functions. default prediction is a function of possibly stochastic quantities other than e(b) r(498);
          or even without cosidering the shock as you recomended me:
          . margins, dydx(ae) warning: cannot perform check for estimable functions. default prediction is a function of possibly stochastic quantities other than e(b) r(498);
          Many thanks in advance for your valuable time and advice. Best regards,

          Comment


          • #6
            Not being familiar with -xtscc-, I don't think I can advise you further here. Perhaps others who have been following the thread can help and will join in.

            Comment

            Working...
            X