Announcement

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

  • ivregress 2sls and ivreg2 with interaction term problems

    Dear Statalist,

    I want to run a two-stage least squares regression as follow: X2 is the endogenous variable and Z is the instrument variable for X2

    Y = a + b1*(X1*X2) + b2*X2 + b3*X3 + b4*X4 + e

    Here is my trial code for your review:

    Code:
    gen XX = X1 * X2
    gen XZ = X1 * Z
    ivregress 2sls Y X3 X4 (X2 XX = Z XZ ) i.ind i.year, vce(cluster gvkey) first small
    May I ask that is the above codes correct? This is cos that I found some variables' t-statistics are very large and not reasonable in comparing to its coefficient size.

    Moreover, if I use -ivreg2-:

    Code:
    ivreg2 Y X3 X4 (X2 XX = Z XZ) i.ind i.year, first savefirst savefprefix(st1)
    It shows the error message of not enough space to run the command. As -ivreg2- should generate the same result as -ivregress-, so do you possibly know how to fix it?

    Many thanks for your help in advance!
    Last edited by Jae Li; 05 Aug 2019, 16:42.

  • #2
    Jae: A few things occur to me. First, the -ivregress- command is correct, but it appears that you have panel data. Is that true? If so, it would be better to use -xtivreg- with the fe option.

    Second, it's very unusual to have an interaction term without both variables appearing in level form. Is X1 a time-invariant variable, and that's why you've dropped it? If so, that's fine. Id X1 is time-varying, it should be included on its own unless you have a very compelling reason not to include it.

    Third, depending on the the distribution of X1, the coefficient on X2 may not make sense. Is X1 = 0 a possible value? Is it the most interesting? If I were you, unless X1 or X2 is binary, I would center X1 and X2 around their means before constructing the interaction. Then I would include the new interaction in the command in place of XX. Everything else can be the same, provided you include X1 if it doesn't drop out.

    I hope this helps.
    JW

    Comment


    • #3
      @Jeff Wooldridge Hi Jeff, thank you for your reply! Yes, I have the firm-year panel dataset. X1 is a time-variant variable and the reason why I didn't include it early is that it showed the error message as follow:

      Code:
      . ivregress 2sls Y X2 X3 X4 (X2 XX = Z XZ) i.ind i.year, vce(cluster gvkey) first small
      X2 included in both exogenous and endogenous variable lists
      r(498);
      X1 and X2 are not binary and what do you mean by
      I would center X1 and X2 around their means before constructing the interaction.
      Here is my data for your convenience:

      ----------------------- copy starting from the next line -----------------------
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double(gvkey fyear Y) float(X2 X1 XX X3) double(X4 Z) float XZ
      1004 1996     .3893348821168493 .15005416            .            .            .                     .   .022895710519446624              .
      1004 1997     .4653784058408889  .3055648 -.0006213948 .00004086949    .05828597    .05828596722772893    .03691815797727448  -.00002294075
      1004 1998    .36124128480407774  .4205541    .04202772   .015053927    .03912865    .03912864467845512   .004097908973594291    .0001722258
      1004 1999    -.3642299485125939  .3317953  .0046245945    .00164823  .0013802256  .0013802256745596734   -.04680481118435945  -.00021645328
      1004 2000    .01726735722579929 .25740355    .01033187    .00256886  -.004753422  -.004753421909888002    .00743340594404824   .00007680098
      1004 2001   -.07551470396289003 .23492795 -.0007141203  -.000203201    -.3030406   -.30304056849768934  -.009418574587445428   6.725995e-06
      1004 2002   -.10861777278297745 .14362174   -.02260957  -.003125648   -.09470968   -.09470968122164215  -.012611051791004711   .00028513043
      1004 2003    -.2304267863797853 .10416707     .1180897   .012860627   -.07692934   -.07692933965673936  -.003422089262890286   -.0004041135
      1004 2004   -.05547208969887356 .15939006   -.05151777   -.00808914   .024295164     .0242951643303968  -.013124727064817456    .0006761567
      1004 2005   .024978409822681624 .29272246    -.1044033   -.02732049    .03580018    .03580018013922705 -.0014850137120063184   .00015504032
      1004 2006    -.0954024032036714 .25169766    .08546003    .02648179   -.07645996   -.07645996225376923 -.0012574489988757508  -.00010746163
      1004 2007    -.0845068810490816  .2058052  -.016820569  -.003605663   -.06510061   -.06510060653090477   .027250866160150503  -.00045837506
      1004 2008   -.16531429339648235 .13576216   .017732024   .002408864   -.05342312   -.05342311901040375    -.0545471906728272   -.0009672321
      1004 2009    1.4695022503098516 .10695989   -.18312024  -.018946454     .5976559     .5793575905263424    .03219268955988557    -.005895133
      1004 2010    .28322566203410976 .12824324 -.0008314206  .0003887125   .068939514    .06893951093984975    .02382430727100004  -.00001980802
      1004 2011    .19216067243208845  .3634054    -.0435303  -.014890214   .015978998   .015978996895930984   .006037552504908899  -.00026281647
      1004 2012   -.12275635882888472 .27930394   .023933755   .006298324    .09675346    .09675345502328128  -.015422316937569291    -.000369114
      1004 2013    .13613445657762357 .20084077   .026585015   .005524121   -.04027607  -.040276065858961374  .0052172415310371995   .00013870044
      1004 2014     .0152078589373028 .26178357  .0008313548   .000437346    .03030743    .03030742979275861  -.004564879773790989  -3.795035e-06
      1004 2015   -.32298545052145455 .14836548   -.02634652 -.0039041904    -.2782805    -.2782804925615589  -.025049533726396706     .000659968
      1004 2016  -.023376372342905728 .16238867  -.009403908 -.0008310482    .19967043    .19967043474316598  -.005200339147208584   .00004890351
      1004 2017    .06091394802607564  .1891309   .013109388   .002410516  -.014076783  -.014076783042401075  .0004984304896323391   6.534119e-06
      1013 1996  -.003657296062134194   .781308            .            .            .                     .  -.010938884583745232              .
      1013 1997   -.10445437797323934  .6266558    .03904557   .024430415    .02112072   .021120719441373746  -.002286911852704349  -.00008929378
      1013 1998    .12183120858460537  .5596372  .0008470226 .00045849686  -.016843753   -.01684375351536137  -.012483406756380308 -.000010573728
      1013 1999     1.603367180672709 .50525403   .071760476     .0362853   .026461944   .026461944418630243  -.007190199637636879  -.00051597215
      1013 2000    .41896046282326493  .7356958    .10808422    .07660134    -.0483946   -.04839460047563916   .011911386056815394     .001287433
      1013 2001    -.3227632234663735 .54299486  -.069439165   -.03781945  -.018599449   -.01859944927040489  -.022346401376802463    .0015517154
      1013 2002    -.3524057753766528 .27411425  -.072309695  -.019858664    .27832627    .27832628763936657   -.01583849984525968     .001145277
      1013 2003    1.2276581860082205  .2362358   -.03794617  -.008939632     .4423902    .44239024033886365  -.008545635127135758    .0003242741
      1013 2004    -.1893792983299024  .2986672    .02635451   .007838542    .04338088    .04338087669636408  -.010401668040611633  -.00027413087
      1013 2005  -.019790204258939518  .3338488  -.011970015  -.003861428   .027617754     .0276177542929707     .0039892211186773  -.00004775104
      1013 2006   -.04950536672542776  .3678787   .005238182  .0018870813    .05796504    .05796504437942833   .005608873684063378  .000029380304
      1013 2007   -.04296424580304587  .4008714 -.0016377056 -.0008069192  -.004782456  -.004782455479516267  -.005197630664214816   8.512189e-06
      1013 2008    -.1703564469336915  .3344481   -.04447687  -.014901514  -.033361256    -.0333612558796354  .0038831359837411226  -.00017270973
      1013 2009     .4392944811163212  .2496523   -.01600357  -.004084575     .2000825     .2000824990785784  -.007204770566765326   .00011530205
      1013 2010   .050816432185755676  .3148358    .01889436   .006505953     .2216326     .2216326168809946  -.008906396372106275  -.00016828063
      1021 1998    -.3270400904256069         .   -.18312024            .   -.19594727                     .                     .              .
      1034 1996    .37921367476642076  .5429029            .            .            .                     . -.0013570361902374146              .
      1034 1997    .08724184735285609 .56652945    .05166875    .02998645   .018507125   .018507125590426426   .007605911575473676   .00039298795
      1034 1998    .02605450408937856 2.1260178   .006716339    .05144883    .03668794    .03668794166654921   .013953675927821377   .00009371762
      1034 1999    1.1030896110808759  .3945288   .017115256   .006737141   .028644087   .028644086549651216    .02637582612505911     .000451429
      1034 2000     .5983367778696518  .5905251    .04266314    .02292502   -.02276361  -.022763610426336525  .0007273917945693834  .000031032818
      1034 2001     .5472473026017204  .6312767    .03137543   .019112866  -.008722925   -.00872292502311871  -.012183357488769518   -.0003822581
      1034 2002   -.14501429844544425  .4632155  -.014266137   -.00662908  -.005839717  -.005839717159742305  -.020999837071571516    .0002995866
      1034 2003     .4509973227932287 .50581324    .19684157    .10021486    .06520628    .06520628262200931  -.025855698931705463    -.005089476
      1034 2004   -.11260232634839872  .3893614   .008921117    .00349514  -.008493598  -.008493597531924024  -.021546574215769734   -.0001922195
      1034 2005   -.16858099052734532  .3554265   .004304598  .0019824472  -.009005173  -.009005172766352954  -.012237103973170904  -.00005267582
      1034 2006   .020444513927999397 2.1260178   .022221206    .11254533  -.005544019  -.005544018714040842  -.007223672270701582   -.0001605187
      1034 2007   -.11344096509420024  .4708317   .013069052   .005969115   .007017793   .007017793054665371   -.01035529517271331  -.00013533389
      1036 1999    .13754778755620975 .25994956    .01486309   .003459714   .017888715   .017888714838773013   -.01744845359985129  -.00025933795
      1038 1996    -.1262567236179785 .19397832            .            .            .                     .   -.00793019559660867              .
      1038 1997   -.14214787874692647  .4503616    .10902151    .04517711  -.036551677   -.03655167748885496  -.006966234443517922   -.0007594694
      1038 1998    .13230616269940607  .3878911   -.02519987  -.009146205   -.19163844   -.19163844013302067    .01199034365447813   -.0003021551
      1038 1999    -.4427742146089716  .3942453   -.08859255  -.032382213    -.0421459   -.04214589785884267  -.037383146641648046     .003311868
      1038 2000   -.34275192223606765 .30870315  -.009011244 -.0017737413   -.03658284  -.036582838876971176  -.016305241485048805    .0001469305
      1038 2001    .16099054481370043  .4393761  .0031157956  .0012885277   .002313474  .0023134740379949417  -.019132256688804125   -.0000596122
      1038 2002    .13631935412533483 .37123665    .01015722   .006662805  -.015051125  -.015051124151796103   -.02476878726572278  -.00025158204
      1038 2003    -.2625819356021558 .29480794    .01455587   .004756961   -.05697068   -.05697067802644928   -.02199043434607633   -.0003200899
      1043 1996    -.5282960061048376         .            .            .            .                     .                     .              .
      1045 1996   -.26233574435461565 .53097475            .            .            .                     .   .001831815104425741              .
      1045 1997    .20753158970198085  .4003251    .05555619   .021677023    .06048309    .06048309362959117   .012838396907865415    .0007132525
      1045 1998    .12429384709892746  .4026795      .039642   .015155034     .1174204    .11742039451375606   .005662490934663424   .00022447246
      1045 1999    -.2713629734076202  .3634226   .019415336   .007224598    .05637984    .05637983693496178  -.028141966990723882   -.0005463857
      1045 2000   -.10187830550899322  .3121225    .05297467   .016506383   -.08761643   -.08761643151575257   .002296956041432729   .00012168048
      1045 2001   -.17725669702063993  .3755867     .1334846    .05237895    -.3111337    -.3111337572062279  -.009108345613024184    -.001215824
      1045 2002   -.11150894629451319 .22537266     .1292169      .029197     .0838859    .08388589814615746  -.011087331897436057   -.0014326706
      1045 2003     .5320570439993246 .21849217    .28171661    .12513778     .5622083     .5622082658422489  -.009898349451330923   -.0027885295
      1045 2004   -.37891788879161276 .20971584    -.0467941  -.008923312    -.2291292   -.22912919521331787   -.03563995035292436    .0016677396
      1045 2005    .08162696828694532  .2030386    .15601628   .033245172    .03076349    .03076348809356039   .010325597457178898    .0016109613
      1045 2006 -.0005064232654928211 .47005895    .01261492   .007105999    .13721085     .1372108452099686  -.006381133532265116  -.00008049748
      1045 2007   -.17290051880288412  .1721502   -.05125244  -.007751074   .018083353   .018083352750788134  -.008265225780987274   .00042361295
      1045 2008  -.004533983933742126  .1598372    -.1643146  -.027522266   -.07844698   -.07844697404652833   -.02481447606951653      .00407738
      1045 2009    1.0366518190453782   .091823   -.02543141 -.0010968033     .5976559     .5793575905263424   .014900286028171679   -.0003789353
      1045 2010    .05088679919770433 .13966556  -.029200356  -.003488859  -.062935024   -.06293502458304699  -.005191144386283938   .00015158327
      1045 2011   -.19695212280142324    .26251   -.04944227  -.013087386   -.12696376   -.12696376743798074   -.00569420151342016   .00028153422
      1045 2013     .2326263024375866 .24084175   -.03969125  -.010346804  -.005690183  -.005690182597997288  -.002086472993234796   .00008281472
      1045 2014     .5407933824578168  .3241753  -.007085282  -.002803429   .023862926     .0238629266332282   .007078081687423047   -.0000501502
      1045 2015   -.10269043685684362 .24784432  -.004787728 -.0012640887    .07277559    .07277558748144657 -.0029494412805628613  .000014121122
      1045 2016    .06920310054400657 .23503803  -.017666504 -.0045105577   -.04058373   -.04058372445235198   .003978663982660938  -.00007028908
      1045 2017   -.09501677634623894 .23849922   .012000147  .0027908266    .02472686   .024726860594290138  -.013565934621432274   -.0001627932
      1050 1996   -.11722887062529111  .0984922            .            .            .                     .   .017749262432855704              .
      1050 1997     .2805263801571533  .1948423  -.008525417 -.0021489954    .05881343    .05881342925131321   .022179641031851473   -.0001890907
      1050 1998    -.5019196109604399 .08836136   -.06691301   -.00684381   -.03854464   -.03854464428150095  -.023477731490348597    .0015709656
      1050 1999    .03738012378640371  .1524473    .03877497   .006945475    .02363031   .023630309384316206  -.028359934681300967   -.0010996555
      1050 2000    -.4503664169243338 .13132577   .025812676   .003971329  -.020072155   -.02007215532163779 -.0036388109734902447  -.00009392745
      1050 2002    .21730624515178198         .    .01980436            . -.0008556675                     .                     .              .
      1050 2003  -.028729522326037538         .    .04244003            .   .005806206                     .                     .              .
      1050 2004    -.3069607955051685         .   .027760306            .  -.010396745                     .                     .              .
      1050 2005    .19322146592358758         .   -.02975475            .   .027675813                     .                     .              .
      1050 2006     .3443873337015737 .27306992   .003107568  .0005453273    .02964698    .02964697778224945  -.003400386166311827 -.000010566931
      1050 2007     .1616944042247621  .2073829   .018709054  .0039616707   -.01985489  -.019854889623820784   -.03060573705698887   -.0005726044
      1050 2008     .1147684237722493  .3210443   -.02123126   -.00656431   -.03119811  -.031198111662108986  .0018687898835746054  -.00003967676
      1050 2009   -.16697050565822746  .1506991    .05507761    .00860272    -.3760616    -.3470109477639198   -.04060886250944088   -.0022366391
      1050 2010    .15886950803181704  .1624078    .06192502   .010939204  .0001812693 .00018126927316188812  -.023050548109873687   -.0014274057
      1050 2011   -.06497377034150886  .1714605  -.005709718  .0006107414    -.0192518  -.019251801073551178   .003979091139936641  -.00002271949
      1050 2012   -.17860298214016504  .1803095  -.007337215 -.0020146205   .022101223    .02210122416727245  -.010263882651230415   .00007530831
      1050 2013    -.3853516359805036         .  -.014730498            .  -.013049152                     .                     .              .
      1050 2015    -.2159404860303201  .1898694  -.008858779  -.001931331   -.10557035   -.10557034588418901 -.0025538233171780674  .000022623757
      1050 2016    .04785648882681855 .12960367   .025108453   .003705581    .10281926    .10281926227940455   .008753730939704652   .00021979264
      end
      ------------------ copy up to and includin

      Many thanks for your help! Looking forward to hearing from you soon!
      Last edited by Jae Li; 06 Aug 2019, 05:29.

      Comment


      • #4
        You should drop the first occurrence of X2.

        If X1 = 0 is not an interesting value then the coefficient on X2 in the model with the interaction won't be meaningful. So use the term

        (X1 - m1)*X2

        instead, where m1 is the sample average of X1.

        Comment


        • #5
          @Jeff Wooldridge Hi Jeff, thank you for your reply! I tried your suggestion to replace XX with (X1 - m1)*X2. However, the unmatched cases between estimated coefficients and t-statistics still exist in -ivregress- regressions.

          Do you possibly have any other advice? I will be more appreciated that!
          Last edited by Jae Li; 06 Aug 2019, 15:13.

          Comment


          • #6
            To expand a little on Jeff's comment, when you have b1 x1 + b2 x2 + b3 x1*x2 b2 is the coefficient on x2 when x1=0. It is quite possible that x1 never equals zero which makes b2 (the coefficient on x2) by itself not interesting and even misleading (since readers may focus on it). One solution is to change the mean of x1 so the mean of x1 equals zero and thus is a value that is reasonably common in the sample (Jeff's solution). Note this doesn't change the estimates substantively. Alternatively, you can explain the issue, and then discuss dy/dx2 at different values of x1.

            In any case, when you have such interactions, you' may want to use margins to examine the influence of dy/x2 (which is b2 + b3*x1) at different values of x1. While this is not difficult in linear models without margins, margins makes it much easier to do, provides standard errors, and handles non-linear models (e.g., logit) easily.

            Comment


            • #7
              @Phil Bromiley Hi Phil, thank you for explaining it in more details! I tried that suggestion to run the -ivregress-. However, the coefficient size and t-statistic value still can't be matched.

              I am thinking about whether I should use the linear instrumental variable estimation for such non-linear instrument regression as the x2 is correlated to (x1*x2). The literature uses two-stage least square analysis so that's why I would like to follow. I may try to use margins as a robustness check but still hope to get the result for 2sls. Many thanks for any feedback you may have!

              Comment


              • #8
                @Jeff Wooldridge Hi Jeff, I have four models ( dynamic panel models ) :

                1- linear model
                GDP = β1 FDX + β2 INF + β4 GOV + β5 GFCF + β6 TRD + β7 LBOR

                2- model with an interactive term
                GDP = β1 FDX + β2 INF + β3 FDX * INF + β4 GOV + β5 GFCF + β6 TRD + β7 LBOR

                3- non-linear model :
                GDP = β1 FDX + β2 FDX2+ β3 INF + β4 GOV + β5 GFCF + β6 TRD + β7 LBOR

                4- non-linear with interactive term
                GDP = β1 FDX + β2 FDX2+ β3 INF + β4 FDX * INF + β5 FDX2 * INF + β6 GOV + β7 GFCF + β8 TRD + β9 LBOR

                Where GDP is the dependent variable, FDX is the endogenous variable and INF, GOV, GFCF, TRD and LBOR are the exogenous variables and lagged variables are used as the instrumental variables.


                What is the Tow Stage Least Square (2SLS) estimation command for each model, please?



                Can I use -xtivreg- with the fe option for the first model? xtivreg GDP GDP_lag1 GDP_lag2 INF GOV GFCF TRD LBOR (FDX= FDX_lag1 GOV _lag1 GFCF_lag1 TRD_lag1 LBOR_lag1), fe

                if yes, what about the rest of the models ( 2, 3 and 4)


                I would be very grateful for any help


                Many Thanks

                Badiah
                Last edited by Badiah Eljahimi; 25 Oct 2021, 17:05.

                Comment

                Working...
                X