Announcement

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

  • Save both first- and second-stage results after (xt)ivreg2 by outreg2?

    1. Please first ssc install "ivreg2" and "outreg2".
    2. Is there a better way to save first- and second-stage results estimated by ivreg2 with outreg2? My example is as follows:
    Code:
    sysuse auto, clear
    
    xi: ivreg2 price i.rep78 (foreign = weight turn trunk), first savefirst
    est restore _ivreg2_foreign
    outreg2 using "ivreg2-12", replace
    xi: ivreg2 price i.rep78 (foreign = weight turn trunk)
    outreg2 using "ivreg2-12", append
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    The author of -outreg2- wrote -ivregress2- specifically for this purpose. Install from SSC and see examples in help. Otherwise, as far as I know, there is no append option in -outreg2-

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      The author of -outreg2- wrote -ivregress2- specifically for this purpose. Install from SSC and see examples in help. Otherwise, as far as I know, there is no append option in -outreg2-
      Indeed, I have read the help file (of outreg2) but did not find similar illustration. And, THERE IS an "append" option in "outreg2".
      Ho-Chuan (River) Huang
      Stata 17.0, MP(4)

      Comment


      • #4
        River: You are correct about the append option, apologies I had not run your code. I do not quite understand what you mean when you say

        did not find similar illustration
        .

        The following using -outreg2- will give you the same output as your example in #1.


        Code:
        ivregress2 2sls price i.rep78 (foreign = weight turn trunk), first
        est restore first
        outreg2 using myfile, cttop(first) replace
        est restore second
        outreg2 using myfile, cttop(second)

        Comment


        • #5
          Originally posted by Andrew Musau View Post
          River: You are correct about the append option, apologies I had not run your code. I do not quite understand what you mean when you say

          .

          The following using -outreg2- will give you the same output as your example in #1.


          Code:
          ivregress2 2sls price i.rep78 (foreign = weight turn trunk), first
          est restore first
          outreg2 using myfile, cttop(first) replace
          est restore second
          outreg2 using myfile, cttop(second)
          Dear Andrew, Thanks for the suggestion. In addition to "ivregress2" (probably you meant "ivregress"), I got the error message
          HTML Code:
          . est restore first
          estimation result first not found
          r(111);
          Any suggestion?
          Ho-Chuan (River) Huang
          Stata 17.0, MP(4)

          Comment


          • #6
            From #2, first

            Code:
            ssc install ivregress2
            before running the code in #4.

            Comment


            • #7
              Originally posted by Andrew Musau View Post
              From #2, first

              Code:
              ssc install ivregress2
              before running the code in #4.
              Thanks a lot, Andrew. It works now.

              Ho-Chuan (River) Huang
              Stata 17.0, MP(4)

              Comment


              • #8
                Hello!

                I have been trying to do the same with xtivreg2 but it is not working.

                Here is my code and the output I get:

                Code:
                *IV WITH FIRST STAGE
                xi: xtivreg2 ln_L (ln_exp_value = wlngdpdest_lcu03) i.year, fe i(region_industry) cluster(region_industry) first savefirst
                est restore first
                outreg2 using myfile.xls , cttop(first) replace

                Code:
                . est restore first
                estimation result first not found
                r(111); t=0.00 9:57:34
                
                end of do-file


                Any ideas? thank you in advance!

                Comment


                • #9
                  #1 through #7 illustrates that you cannot output xtivreg2 first stage results using outreg2. So you have 2 options

                  1. Install ivregress2 from SSC and follow the instructions in this thread, or
                  2. Keeping with xtivreg2, use esttab

                  Code:
                  eststo clear
                  *IV WITH FIRST STAGE
                  eststo: xi: xtivreg2 ln_L (ln_exp_value = wlngdpdest_lcu03) i.year, fe i(region_industry) cluster(region_industry) first savefirst savefprefix(st1)
                  esttab est1 st1* using myfile.xls, replace

                  Comment


                  • #10
                    I have the similar query. I am using two different 2sls regression models as follows:

                    Y = Controls ( X1 = Instrument_1 Instrument_2)
                    Y = Controls ( X2 = Instrument_1 Instrument_2)

                    The only different between these two models is that my primary independent variable changes from X1 to X2. Otherwise control variables and primary dependent variable is the same. I want to bring the regression output of 1st stage and 2nd stage regression for both of these above 2 models in one excel file with 3 decimal places.

                    However, the problem I am facing is that STATA copy pastes the same 1st stage and 2nd stage regression output for Model-2 as of Model-1. I am using following codes.

                    ivregress 2sls Y Controls (X1 = Instrument_1 Instrument_2), first
                    est restore first
                    outreg2 using results, replace excel dec(3)
                    est restore second
                    outreg2 using results, append excel dec(3)

                    ivregress 2sls Y Controls (X2 = Instrument_1 Instrument_2), first
                    est restore first
                    outreg2 using results, append excel dec(3)
                    est restore second
                    outreg2 using results, append excel dec(3)

                    Comment


                    • #11
                      Try to have

                      Code:
                      eststo clear
                      in between the two blocks of code. If this does not solve it, present a reproducible example using dataex or one of Stata's example data sets.

                      Comment


                      • #12
                        These are my four 2SLS regression models:

                        ivregress 2sls Y Control_1 Control_2 Control_3 Control_4 Control_5 Control_6 Control_7 Control_8 Control_9 Control_10 (X1 = Instrument_1 Instrument_2), first
                        ivregress 2sls Y Control_1 Control_2 Control_3 Control_4 Control_5 Control_6 Control_7 Control_8 Control_9 Control_10 (X2 = Instrument_1 Instrument_2), first
                        ivregress 2sls Y Control_1 Control_2 Control_3 Control_4 Control_5 Control_6 Control_7 Control_8 Control_9 Control_10(X3 = Instrument_1 Instrument_2), first
                        ivregress 2sls Y Control_1 Control_2 Control_3 Control_4 Control_5 Control_6 Control_7 Control_8 Control_9 Control_10 (X4 = Instrument_1 Instrument_2), first

                        I want to bring results of both 1st stage and 2nd stage regression for all of these four models in one excel file with 3 decimal places. I am using following codes for results output:
                        outreg2 using results, replace excel dec(3)
                        outreg2 using results, append excel dec(3)


                        following is my sample data:

                        Code:
                        * Example generated by -dataex-. To install: ssc install dataex
                        clear
                        input long firmid float Y byte X1 float(X2 X3 X4 Instrument_1 Instrument_2) byte Control_1 float Control_2 byte(Control_3 Control_4) float(Control_5 Control_6 Control_7 Control_8 Control_9 Control_10)
                         1        . 1 .167 .278  .6931472 0 .143 0  6.670259 0 0  2.195045          0           0  .15292925  .09155466  .3478433
                         1        . 1 .167 .278  .6931472 0 .143 0  6.588926 1 0  1.001695          0           0  .14126548   .0994498 .24796863
                         2        . 0    0    0         0 0 .083 0  5.619005 1 0  2.910694  .23590516   .08526387  .02889901   .9454166   .373393
                         2        . 0    0    0         0 0 .083 0  6.575638 1 0  2.686605   .4002618  .004500957 .024768505   .8075809 .17650464
                         2 .2180372 0    0    0         0 0 .083 0  6.672377 1 1   2.12065  .37214655   .11105797  .02869392   .8887459  .2063778
                         2 .2936769 1   .1  .18  .6931472 0 .083 0  6.805904 1 0  .8898335   .4881782           0 .016597208   .9662221  .4256044
                         2 .6583127 1 .111 .198  .6931472 0 .083 0  6.843047 1 1  1.533329   .5128571           0 .006899303  1.0960473  .2489924
                         2 .1472668 1 .111 .198  .6931472 0 .083 0  6.813955 1 1  1.347958   .5373243           0   .0772715  1.0687627  .2739401
                         2 .0130525 1 .111 .198  .6931472 0 .083 0   6.71405 1 0  .5789255   .4266763   .02973658   .0647687  1.2173065  .3686417
                         3        . 0    0    0         0 0 .133 0  5.360353 1 1  1.319554          0           0   .4868421  .04887218  .3206087
                         3        . 0    0    0         0 0 .133 0   5.50289 1 0  2.278167          0           0   .4462103   .0403423  .5544439
                         3 .3781362 0    0    0         0 0 .133 0  5.408068 1 1  1.275768          0           0   .4036738  .06317204  .5092649
                         4        . 1 .167 .278  .6931472 0  .08 0  5.316506 0 1  2.535091 .001416008   .05458899 .000536697  .21714285 1.5553493
                         4        . 1 .143 .245  .6931472 0  .08 0  5.509544 0 0  4.165987 .000793399  .000480897  .09653819  .21015795  3.026734
                         4        . 1 .143 .245  .6931472 0  .08 0  6.537719 0 0  1.137273          0           0   .0795885  .11429835 2.0036337
                         4        . 1 .142 .244  .6931472 0  .08 0   6.72145 1 0  3.127966          0           0  .14301102  .12392352  2.156743
                         4 .6267393 1 .143 .245  .6931472 0  .08 0  7.356216 1 0  2.221713  .14036657   .14221853   .0839134   .0842327  1.324527
                         4  .095713 1 .143 .245  .6931472 0  .08 0  7.202885 1 0  .8099924  .10965533   .16608353    .036254  .11739746 1.7236214
                         4 .0878166 1 .286 .408 1.0986123 1  .08 0  7.305255 1 0  2.031314  .05019824   .10973725  .05019824  .11988442  1.623895
                         4 .0124391 1 .333 .444 1.0986123 1  .08 0  7.147638 1 0  2.999438          0           0 .025961764  .15561324  1.962664
                         4 .2215257 1 .333 .444 1.0986123 1  .08 0  7.660209 1 0  2.536171  .11205354  .017623222  .08580718  .11572896 1.2479378
                         5        . 0    0    0         0 0  .08 0  5.098854 1 1  1.302788  .06090922   .03044545   .2734658  .17117937  .4916016
                         5        . 0    0    0         0 0  .08 0   5.10412 1 0  2.350877          0   .06068646  .22870205  .17585413  .5877343
                         5  .107992 0    0    0         0 0  .08 0   4.98275 1 0  4.027356          0           0   .1161748  .21028963   .891403
                         5 .3556655 0    0    0         0 1  .08 0  5.265412 1 0  3.196363          0     .090732   .0860763  .17622955  .6173435
                         5 .0350082 0    0    0         0 1  .08 0  5.232786 1 0  2.111114          0   .05839393  .09071933  .19472116  .6088019
                         6        . 1  .09 .164  .6931472 0 .133 0  8.323074 1 0  1.381452  .07185876           0 .003424159          0 .23330727
                         6        . 1   .1  .18  .6931472 0 .133 0  8.643474 1 0  1.114615  .05577296           0 .012392032          0 .27839422
                         6 .1786354 1   .1  .18  .6931472 0 .133 0  8.718434 1 0  1.174101  .05200667           0 .013328754          0  .3219449
                         6 .0084918 1 .091 .165  .6931472 0 .133 0  8.779881 1 1  1.098194  .05974993           0  .03943341          0  .3064833
                         6 .0971444 1   .1  .18  .6931472 1 .133 0  8.781847 1 0  1.258458  .06299406           0  .02925601          0  .3341442
                         6 .0699918 1   .2  .32 1.0986123 1 .133 0  8.790741 1 0  1.368817  .05957615           0 .025026243          0  .3477476
                         6 .0869313 1 .222 .346 1.0986123 1 .133 0   8.80623 1 0  1.344824   .0392618           0  .03067843          0   .352542
                         7        . 1 .076  .14  .6931472 0 .143 0  7.853216 1 0  3.595824  .27490285  .008818959  .04316239  .22836053  1.559401
                         7        . 1 .083 .153  .6931472 0 .143 0  7.938802 1 1  4.001382   .3191869  .013908702 .031383738  .27639088  .5147718
                         7 .4707019 1 .125 .219  .6931472 0 .143 0  7.548556 1 1   1.02784   .2239199  .017386723 .003161222  .20179136  .7417573
                         8        . 0    0    0         0 0 .143 0  9.370075 1 0   2.39497   .4503921   .04594272   .0989601  .58523697 .23926957
                         8        . 0    0    0         0 0 .143 0  9.621721 1 0  .9360583   .4656372   .02790112  .07482272   .5961297 .23632617
                         8  .013066 0    0    0         0 0 .143 0  9.556127 1 0  1.051774   .3897106   .05272097  .08442432    .626778 .26858047
                         8 .0729185 0    0    0         0 0 .143 0  9.557187 1 0  1.445413   .4245723     .022904  .09543334   .6817475 .24513035
                         9        . 1 .125 .219  .6931472 0 .111 0  7.676891 1 0  2.223286  .19268733   .05950229  .04434867   .9299782  .9374018
                         9        . 1 .222 .345 1.0986123 0 .111 0  7.999544 1 0  1.750802  .26748556   .05843066  .04957041   .9021345 1.0263364
                        10        . 1 .125 .219  .6931472 1 .111 1  7.579679 0 0 -.8789069   .7760348  .017875383    .154239  .11899898   .492866
                        10        . 1 .143 .245  .6931472 1 .111 1  7.509335 1 1 -.9153821   .7760348   .02191781   .0909589  .13589041  .5009405
                        10 .1337435 1 .143 .245  .6931472 1 .111 1  7.548556 1 0 -.7770399   .7760348   .02476291  .11116965  .11538462  .4805458
                        10 .0642795 1 .167 .278  .6931472 1 .111 0   7.51043 1 0 -.4385285   .7760348   .02627258   .0821018  .13081555  .5141277
                        11        . 1 .067 .125  .6931472 0 .087 0  10.85688 1 0  2.151078  .12262478   .04000771 .066101365   .8498555  .5887009
                        11        . 1 .125 .219 1.0986123 0 .087 0 10.746842 1 0  3.004662  .09078588   .04362885  .06462578   .7737022 .57257843
                        11 .0319797 1  .17 .282 1.0986123 0 .087 0 10.709115 1 0  3.594614  .05370627   .13169652 .069903046   .7410973  .6031451
                        11 .1446595 1 .167 .278 1.0986123 0 .087 0 10.814525 1 0  1.467005   .1449797   .13639471  .05571193   .7756042 .54469466
                        11 .0146019 1 .154  .26 1.0986123 0 .087 0 10.938592 0 0  2.018156   .2276053   .02662144   .0580557   .8613341  .3900148
                        11 .1254967 1 .182 .298 1.0986123 0 .087 0   11.1073 1 0   1.83439  .17858857  .023028685  .09603036    .819056  .4441822
                        11 .1265605 1 .182 .298 1.0986123 0 .087 0  11.19054 1 0  1.140329  .16364816   .01405262  .16195025   .7695259  .4452607
                        11 .0813631 1 .182 .298 1.0986123 1 .087 0 11.278935 1 1   1.04282  .19144017   .03140124  .11473773    .792398 .37706175
                        11  .034435 1 .077 .142  .6931472 1 .087 0 11.172756 1 0  .8827064  .22117613  .029621303  .10825546   .8721563  .4268419
                        11 .0141084 1  .25 .375 1.3862944 1 .087 0 11.097562 1 1   .906329  .25627935   .02451144  .10222694   .9776549  .4228094
                        11 .0837349 1 .167 .278 1.0986123 1 .087 0  10.85925 1 1  .3420519   .3137293  .031703614  .13256301   1.151616  .4007288
                        11  .175896 1   .2  .32 1.0986123 1 .087 0 10.822754 0 0  .9627872  .22658478  .036012683  .12066043   1.206405  .4409994
                        11  .042627 1  .25 .375 1.3862944 1 .087 0 10.907075 1 0  1.158489  .19464453  .024761276  .14295925  1.1801103 .50008905
                        11 .0523604 1  .25 .375 1.3862944 1 .087 0 10.862761 1 0  1.195856   .1603763  .011495134  .12581424  1.2123343  .5508044
                        12        . 0    0    0         0 0 .143 0  8.711443 1 0  1.707613  .08876812    .0736166  .15299736   .5762516  .9561454
                        12        . 0    0    0         0 0 .143 0  8.778326 1 0  1.670156  .02711029   .08179297  .05375847  .59149724  .9513629
                        12 .0030739 0    0    0         0 0 .143 0  8.850804 1 0  1.479259  .08567335  .017908309  .05888252   .5879656 1.0003316
                        12 .0425033 0    0    0         0 0 .143 0  9.005896 1 0  1.295988  .10673537  .034106243  .04269415  .59244263 1.0307052
                        12 .0727007 0    0    0         0 0 .143 0   9.10864 1 0  1.433117  .08922838   .06465183  .04240009  .59105504 1.0432297
                        12 .0269416 0    0    0         0 0 .143 0  9.136478 1 0  1.570485  .08548665   .03951335 .037144702   .6547158  1.118065
                        12 .0258915 0    0    0         0 0 .143 0  9.230339 1 0  1.539825  .08792394  .071456574  .03342482   .6603607  1.106647
                        12 .0043527 1 .125 .219  .6931472 1 .143 0  9.234056 1 0  1.730175  .08925781   .05253906  .03818359   .6886719  1.220859
                        12 .0011287 1 .125 .219  .6931472 1 .143 0  9.247058 1 0  2.326788  .07441681   .03797957  .03489493   .7098516 1.3163985
                        12 .0043216 1 .111 .198  .6931472 1 .143 0   9.25646 1 0  3.223516  .05796409    .0341864  .04956073   .7280366  1.280631
                        12 .0421487 1 .222 .346 1.0986123 1 .143 0  9.232004 1 0  3.865063  .05646345   .03121636  .06869557   .7500734 1.3035605
                        12 .0138013 1 .222 .346 1.0986123 1 .143 0  9.339261 1 0   3.04257  .05625879   .02153657  .04878692    .780327 1.2194295
                        12 .0500059 1 .222 .346 1.0986123 1 .143 0  9.457981 1 0   2.99809  .04777518  .020686964  .12099922   .7484778  1.245355
                        12 .0332513 1 .222 .346 1.0986123 1 .143 0  9.524567 1 0  1.921815  .02621969   .03060181  .09947415   .7505843 1.1742079
                        13        . 0    0    0         0 0 .087 0   7.98177 1 0  1.554322          0           0   .1369993   .7702615 .40098795
                        13        . 0    0    0         0 0 .087 0  8.099998 1 0  1.056766          0           0  .17731404   .7882233  .4136688
                        13 .1044543 0    0    0         0 1 .087 0    8.1118 1 0  1.064939          0           0  .12039585   .8808334  .3409489
                        13 .0493355 1 .083 .153  .6931472 1 .087 0  7.796462 1 1  .6566874  .05838857           0  .11612308  1.2904958  .3843117
                        13  .016464 1   .1  .18  .6931472 1 .087 0  7.856868 1 0  .8170201  .04946939  .005496598  .11374457  1.3184538  .3787912
                        13 .0338956 1   .1  .18  .6931472 1 .087 0  7.753828 1 1  .6084456  .04265225  .012186356   .1000944   1.518095   .381408
                        13 .0308093 1 .111 .198  .6931472 1 .087 0  7.825104 1 0  1.015819  .02836997   .01134799   .1269818  1.4940003  .4411161
                        13 .0481399 1 .143 .245  .6931472 1 .087 0  7.496035 1 1   .982059  .02365501  .015770007  .04470734  1.6209205  .4049875
                        14        . 1   .2  .32 1.0986123 0 .133 0  6.768863 1 0  12.16139          0           0   .1789832          0  .4558937
                        14        . 1   .2  .32 1.0986123 0 .133 0  6.921661 1 0  8.735854          0           0  .14229389          0  .4461802
                        14 .0263091 1   .2  .32 1.0986123 0 .133 0  7.071064 1 0  10.55435          0           0   .1798879          0  .4616893
                        14 .0111886 1 .182 .298 1.0986123 0 .133 0  7.476869 1 0  11.61536          0           0  .13963887          0 .38718405
                        14 .0164651 1 .182 .298 1.0986123 0 .133 0  7.868981 1 0  5.857128          0  .000344181  .08589239          0 .34451935
                        14 .0533523 1  .25 .375 1.3862944 1 .133 0  8.072218 1 0  6.941312          0  .000249672 .067598775          0   .319307
                        14 .0481224 1  .25 .375 1.3862944 1 .133 0  8.153005 1 0  7.013286          0 .0000287869  .05409062          0  .2787408
                        14 .0988625 1 .273 .397 1.3862944 1 .133 0  8.262946 1 0  6.495554  .05137331  .001547389  .06599613          0 .23958986
                        14  .093229 1 .417 .486 1.7917595 1 .133 0  8.343411 1 0   7.58737  .04740148   .00654388 .063130595          0  .2279226
                        14 .0915854 1   .4  .48  1.609438 1 .133 0  8.488958 1 0  9.099871  .04098091  .005122614  .06719059          0 .21968286
                        14 .0497909 1 .375 .469 1.3862944 1 .133 0  8.675752 1 0  8.899597 .033998396  .004232732  .05577648          0 .20283583
                        14 .0563682 1 .364 .463  1.609438 1 .133 0  8.825046 1 0  7.842003  .03738331   .02791621   .0553914          0  .1955709
                        15        . 1 .111 .198  .6931472 0 .133 0  7.729893 1 0  2.726783  .03750355   .02123622 .035458125 .015516226 .15768677
                        15        . 1 .111 .198  .6931472 0 .133 0   7.77108 1 0  1.656519  .07268574   .01962397  .03465203 .015837843  .1853495
                        15 .0170711 1 .111 .198  .6931472 0 .133 0  8.031221 1 0  1.841752  .07399164  .009211847 .026454885 .013931718 .14128068
                        15 .0634942 1 .083 .153  .6931472 0 .133 0  8.054078 1 0   1.88715  .05037183           0  .04792475 .015063878 .20962465
                        15 .1204542 1 .214 .337 1.3862944 0 .133 0  7.967731 1 0  1.942151 .028410075           0  .07258428 .011987666 .28155974
                        15 .0055379 1 .231 .355 1.3862944 1 .133 0  8.311742 1 0  3.289813          0  .020017685  .08544973 .009750946 .22391348
                        end
                        label values firmid firmid1
                        label def firmid1 1 "0876711D LN Equity", modify
                        label def firmid1 2 "1218069D LN Equity", modify
                        label def firmid1 3 "1334987D LN Equity", modify
                        label def firmid1 4 "1561649D LN Equity", modify
                        label def firmid1 5 "1638414D LN Equity", modify
                        label def firmid1 6 "1655637D LN Equity", modify
                        label def firmid1 7 "3572335Q LN Equity", modify
                        label def firmid1 8 "8190169Q LN Equity", modify
                        label def firmid1 9 "9408593Q LN Equity", modify
                        label def firmid1 10 "AA/ LN Equity", modify
                        label def firmid1 11 "AAL LN Equity", modify
                        label def firmid1 12 "ABF LN Equity", modify
                        label def firmid1 13 "ACA LN Equity", modify
                        label def firmid1 14 "ADM LN Equity", modify
                        label def firmid1 15 "ADN LN Equity", modify

                        Comment


                        • #13
                          Thanks for the data example. Two points

                          1. You cannot use ivregress. From #6: First

                          Code:
                          ssc install ivregress2
                          2. -append- for subsequent regressions, do not -replace-

                          Code:
                          ivregress2 2sls Y Control_1 Control_2 Control_3 Control_4 Control_5 Control_6 Control_7 Control_8 Control_9 Control_10 (X1 = Instrument_1 Instrument_2), first
                          est restore first
                          outreg2 using myfile, cttop(first) replace
                          est restore second
                          outreg2 using myfile, cttop(second)
                          
                          ivregress2 2sls Y Control_1 Control_2 Control_3 Control_4 Control_5 Control_6 Control_7 Control_8 Control_9 Control_10 (X2 = Instrument_1 Instrument_2), first
                          est restore first
                          outreg2 using myfile, cttop(first) append
                          est restore second
                          outreg2 using myfile, cttop(second) append

                          Comment


                          • #14
                            Andrew Musau
                            It's very good command for 2sls and it eased my work thank you.i have one question,that how can i use # 13 code for GMM ,i want to check endogeneity through GMM (in first stage using lag of independent variable. as an instrument ,then second stage using the first one as Independent variable).could you please guide me that how to outreg result of GMM ?
                            best regards

                            Comment


                            • #15
                              Do you use Stata's gmm command to estimate the model? If so and you run two separate estimations, you can do something as follows:

                              Code:
                              gmm....
                              est restore first
                              outreg2 using myfile, cttop(first) replace
                              gmm...
                              est restore second
                              outreg2 using myfile, cttop(second)
                              If not, show an example of your syntax.

                              Comment

                              Working...
                              X