Announcement

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

  • Automated means to export elasticity outputs after estimating Almost Ideal Demand System (AIDS) using the Stata command 'aidsills'?

    Dear Statalisters, I have been running AIDS demand systems for several population subgroups using the aidsills command proposed by Lecocq, S., & Robin, J.-M. (2015). Estimating almost-ideal demand systems with endogenous regressors. The Stata Journal, 15(2), 554-573.

    After estimation, I'm able to use outreg2 to readily export the main demand system output to word. However, after predicting the elasticities, outreg2 is not able to export the elasticity values. Does anyone have experience with how that can be achieved seamlessly?

    Many thanks for your help in advance!

  • #2
    Provide a data example and show exactly what you want extracted.

    Comment


    • #3
      Andrew, thanks for your response. I provide an example below. I estimate an AIDS model with 3 goods, their shares being w1, w2 and w3, with corresponding prices P1, P2 and P3.
      Afterwards, I calculate the elasticities. My challenge, for which I seek for help, is to find an automated way to export these elasticities to Microsoft Word or Excel.

      The command and the associated output are shown below.
      . aidsills w1 w2 w3, prices(P1 P2 P3) expenditure(e) symm hom
      Iteration = 1 Criterion = .04081038
      Iteration = 2 Criterion = .0007966
      Iteration = 3 Criterion = .00005062
      Iteration = 4 Criterion = 3.761e-06
      AIDS - PROPER ESTIMATION WITH FIXED ALPHA_0 = 0
      HOMOGENEITY AND SYMMETRY CONSTRAINED ESTIMATES
      Equation Obs Parms RMSE "R-sq" F( 4, 38805) Prob > F
      w1 38810 4 .2237592 0.0654 905.62 0.0000
      w2 38810 4 .2348778 0.0375 504.67 0.0000
      w3 38810 4 .1575217 0.0290 386.76 0.0000
      Coef. Std. Err. z P>z [95% Conf. Interval]
      w1
      gamma_lnP1 .0473186 .006801 6.96 0.000 .0339888 .0606484
      gamma_lnP2 .0161468 .0017981 8.98 0.000 .0126225 .0196711
      gamma_lnP3 -.0634654 .0069569 -9.12 0.000 -.0771007 -.0498302
      beta_lnx -.075245 .001507 -49.93 0.000 -.0781987 -.0722913
      alpha_cons .9764725 .0094441 103.40 0.000 .9579624 .9949825
      w2
      gamma_lnP1 .0161468 .0070777 2.28 0.023 .0022747 .0300189
      gamma_lnP2 .0001204 .0017877 0.07 0.946 -.0033835 .0036243
      gamma_lnP3 -.0162672 .0072459 -2.25 0.025 -.0304689 -.0020655
      beta_lnx .0529543 .0015879 33.35 0.000 .0498422 .0560665
      alpha_cons .0458692 .0099487 4.61 0.000 .0263701 .0653683
      w3
      gamma_lnP1 -.0634654 .0045772 -13.87 0.000 -.0724366 -.0544943
      gamma_lnP2 -.0162672 .0011448 -14.21 0.000 -.0185109 -.0140235
      gamma_lnP3 .0797327 .0046506 17.14 0.000 .0706177 .0888477
      beta_lnx .0222907 .0010567 21.09 0.000 .0202195 .0243618
      alpha_cons -.0223417 .0066049 -3.38 0.001 -.035287 -.0093964

      I can use outreg to export the main estimation results seamlessly to Word, with the following command:

      . outreg2 using "my example", word dec(3) replace
      my example.rtf
      dir : seeout
      Next, I calculate the elasticities, with the outputs below

      . aidsills_elas

      PREDICTED SHARES, BUDGET AND (UN)COMPENSATED OWN-PRICE ELASTICITIES

      shares budget u_price c_price
      b/se b/se b/se b/se

      w1 0.496*** 0.848*** -0.758*** -0.338***
      (0.001) (0.003) (0.013) (0.013)
      w2 0.369*** 1.144*** -1.005*** -0.583***
      (0.001) (0.004) (0.005) (0.005)
      w3 0.135*** 1.165*** -0.409*** -0.252***
      (0.001) (0.008) (0.035) (0.034)

      * p<0.05, ** p<0.01, *** p<0.001

      UNCOMPENSATED CROSS-PRICE ELASTICITIES

      P1 P2 P3
      b/se b/se b/se

      w1 -0.758*** 0.039*** -0.129***
      (0.013) (0.003) (0.014)
      w2 -0.095*** -1.005*** -0.044*
      (0.019) (0.005) (0.019)
      w3 -0.629*** -0.127*** -0.409***
      (0.034) (0.008) (0.035)

      * p<0.05, ** p<0.01, *** p<0.001

      COMPENSATED CROSS-PRICE ELASTICITIES

      P1 P2 P3
      b/se b/se b/se

      w1 -0.338*** 0.352*** -0.014
      (0.013) (0.003) (0.014)
      w2 0.472*** -0.583*** 0.111***
      (0.019) (0.005) (0.019)
      w3 -0.051 0.303*** -0.252***
      (0.034) (0.009) (0.034)

      * p<0.05, ** p<0.01, *** p<0.001


      Is there any way to export these elasticity outputs from Stata to Word or Excel?

      Thanks for any suggestion!
      Last edited by Isaac Ansah; 02 Aug 2020, 07:33.

      Comment


      • #4
        I don't use this command. What I need is a sample of the data or any data that can produce estimates. For example, you can copy and paste the output from the following:

        Code:
        ssc install dataex
        dataex w1 w2 w3 P1 P2 P3 e in 1/30

        Comment


        • #5
          Thanks Andrew. I'm learning a lot from you. Below is the example data set.


          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input float(w1 w2 w3 P1 P2 P3 e)
           .5198307 .22950464 .25066462  .6322585  .3419917  .6743702 196.74147
           .3166019   .406701  .2766972 1.9719806  5.877278  3.579139 1119.9675
                  1         0         0 1.9719806  5.877278  3.579139 1369.4755
           .2208666  .2111906  .5679428  1.919753  5.764501  3.421123 2448.7585
           .3915554  .6084446         0  3.373136 17.308832 4.6693764      2119
           .7692308 .23076925         0 2.0127728  6.162648 3.5314586   210.415
           .2733759  .6064589 .12016522  3.618754 18.274466 4.4623036  1249.139
           .7156863 .28431374         0  3.564819 20.447567  5.022873  500.9775
           .4660194  .4045307 .12944983  .5998389 .39663175  .7655308 122.25653
           .5006207  .3876474 .11173184 .59135324  .4020671  .7733294  240.3295
           .5976676  .3498542 .05247814   2.08382  5.562483  3.649245 1587.1017
                  1         0         0 1.9873953  5.816913   3.40277 1141.2295
           .5478261 .45217395         0  1.973335  5.741402  3.426661  693.9042
           .3534595 .29411766  .3524229  .5097418  .3557697  .6609849 537.50354
           .3769086 .57808733 .04500402  .5079554  .3539383  .6582261 308.44705
                  1         0         0 1.9436172  5.718124  3.439276 163.50024
            .370981 .52899146 .10002748 1.9436172  5.718124  3.439276  713.1709
          .50287354  .4166667 .08045976 .52528757  .3751918   .726401   182.583
                  .         .         . 3.6270344 14.826605 4.0454845         .
           .8518518 .14814815         0  2.095805  5.467301 3.4500675 4512.8574
           .2997602 .55635494 .14388488  .4859272  .3416215  .6455669 208.88257
           .3699003  .3037171  .3263826  3.462616 16.188543  4.313952 1841.7065
           .4690914  .3524499  .1784587  .4280832  .3454781  .6017218  405.6197
           .4674766  .2977099 .23481347  .4280832  .3454781  .6017218 153.07288
           .3897365   .443828  .1664355  3.511034  10.89066  5.205473  6151.031
           .5741056  .4258944         0  3.511034  10.89066  5.205473  3924.515
           .8884398 .11156023         0  3.511034  10.89066  5.205473  6638.945
           .4265626 .25925517  .3141821  .4719237  .3461879  .6313164   90.4693
           .8461539 .15384616         0  3.420138  15.22427   4.88493  4887.147
           .3225679 .55454904 .12288301  .5103888  .3261841  .6839769 277.70313
           .4077253 .54130906 .05096567 1.9337118  5.703216   3.42879  661.3021
           .3590176  .4926559 .14832652  1.905766  5.678155 3.3918736  635.6898
          .25997046  .6868538 .05317578  3.282437 18.638702 4.7246103 2316.0525
           .4808694 .51913047         0  .5068112  .3307435  .6939639  74.14899
           .3239024 .17560974  .5004878  3.133248 12.929688  4.490777 2507.3926
           .1726104  .6866405 .14074908  .4946329  .3464147  .6092384  463.5777
          .27508092  .5177994 .20711975  3.209767 11.019682  5.080469  2956.437
           .7506438         0  .2493561  3.284741  11.61066  4.890257 1075.7955
           .5434783  .1521739  .3043478  3.284741  11.61066  4.890257 1299.0586
          .17548747  .4066852  .4178273  3.284741  11.61066  4.890257  3740.725
           .3290799 .15110813   .519812  3.223135 10.251724  5.024091 2207.9028
           .4760915         0  .5239085  1.830173  5.903948  3.647533 1790.6643
           .3620365 .23696937  .4009941  1.830173  5.903948  3.647533  1304.791
                  1         0         0 3.2010894 11.078074  4.894508 1071.5887
           .4530549 .54694515         0  3.135166 12.014223   4.81279 1235.7515
          .50155765  .4984423         0 1.7589617  5.712123  3.288775  791.8645
           .5997499         0  .4002502   3.13351 11.621902  4.892722  777.4578
           .4732041  .5267959         0 3.1727266 11.305132    4.7767 1360.3467
           .5608132  .4391868         0 1.7559056  5.743616 3.3538356 528.16614
                  0 .18897638  .8110236  3.138939 12.886278    4.6916  4262.828
          end


          Many thanks for your willingness to help.
          Last edited by Isaac Ansah; 02 Aug 2020, 09:51.

          Comment


          • #6
            Thanks for the data example. The command does not save these results in e or r, so the only way to export them (apart from copying and pasting) is to log the session. Here is one way to retrieve the results from the log and then export to Excel.

            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input float(w1 w2 w3 P1 P2 P3 e)
            .24652484  .7534752         0 214 959 458  71.00982
             .4802026  .3029835  .2168139 213 407 587  309.6257
             .4040258  .5959742         0 478 611 479  112.2794
            .29783222  .7021677         0 138 373 869  337.5909
             .3278136  .5703448 .10184167 227 433 392  682.8024
              .317041  .6829591         0 823 403 654 140.03003
            .15758227  .8424177         0 634 455 834  343.0483
            .29119638 .58961624 .11918735 427  87 214   203.601
             .2247934  .7752066         0 888 881  54 170.97826
                .6544     .3456         0 113 244 339       390
             .4111133  .3868818 .20200492 128 674  27 292.81464
             .3725173  .3538711 .27361166 754 595  62  180.6817
              .222281  .4398792  .3378399 315 258  56       331
             .2637257 .54542017  .1908541 727 235 633 161.62846
               .38775  .3877084 .22454157 128 359 412  308.2336
             .3844598  .6155401         0  67 396  22   134.516
            .53816795  .4618321         0 505 687 399 215.54797
             .4696538  .5303463         0 955 187 887 109.27248
             .8399391 .16006097         0 521 848 176   839.475
             .4227686 .57723147         0 813 426 882  70.16249
             .3721109  .4429892 .18489987 136 556 164 136.02841
            .59104043  .2724181 .13654147 206 314  42 143.21605
             .5343077 .46569225         0 785 118 752  269.2887
            .28466257  .5202454 .19509204 545 244 184  188.9137
             .2911153  .7088847         0 630 752 948   192.556
            .28824157  .3493976  .3623608 360 429 812 133.30809
             .1208146  .8406568 .03852858 788 340 485 1038.9515
             .3185031  .6814969         0 527 558 361 173.17377
             .5915493  .4084507         0 788 461 147  204.2705
            .46811435   .371083 .16080263 342 318 224 180.11316
             .3036649  .4345549  .2617801 295 409 179 175.76294
             .3456194  .4386319  .2157487 561 700 368 195.38664
             .4534616  .3940598 .15247855 564 971 365 270.56656
             .2714154 .56094563 .16763893 626 545 987  248.0918
             .6113529  .2385285  .1501187 272 601 491  244.6018
             .7182686  .2817315         0 739 992 896   381.249
            .15248796   .847512         0 203 211 644 232.07095
             .5604113  .3239075 .11568125 941 895 904  451.9021
             .3263366  .5239604 .14970297 150 404  40 297.50757
             .4324876 .26130065  .3062117 518 665 571 249.96446
                    0         1         0 622 534 137  97.74684
             .2977528 .56179774 .14044945  60 445 428 263.85883
             .3022211  .2852988  .4124802 170 100 697  844.9149
             .3587786  .6412214         0  27  40 260  390.8525
            .34619015  .4231299    .23068 754 128 573 274.78912
             .3755842  .4423459  .1820699 349 910 645  214.8418
             .3807732  .3989052  .2203216 990 283 908  97.26706
             .6136555  .3863445         0 548 533 271  83.96189
             .5419847  .4580153         0 212 762 568  174.0292
             .5786779  .4213222         0 908 551 366  384.5272
            end
            *type -findit aidsills- to install
            aidsills w1 w2 w3, prices(P1 P2 P3) expenditure(e)
            preserve
            qui log using firstfile, name(log1) text replace
            aidsills_elas
            log close log1
            insheet using "firstfile.log", clear
            gen obs=_n
            levelsof obs if regexm(v1, "PREDICTED"), local(start)
            levelsof obs if regexm(v1, "log close log1"), local(end)
            keep if inrange(obs, `start', `=`end'-1')
            drop obs
            export excel using myfile, replace
            restore
            These will be saved in myfile.xls in your current working directory.

            Res.:

            Code:
            . import excel myfile.xls, clear
            (1 var, 40 obs)
            
            . list, sep(0)
            
                 +---------------------------------------------------------------------+
                 |                                                                   A |
                 |---------------------------------------------------------------------|
              1. | PREDICTED SHARES, BUDGET AND (UN)COMPENSATED OWN-PRICE ELASTICITIES |
              2. |      -------------------------------------------------------------- |
              3. |                       shares       budget      u_price      c_price |
              4. |                         b/se         b/se         b/se         b/se |
              5. |      -------------------------------------------------------------- |
              6. |      w1             0.390***     1.117***    -0.997***    -0.561*** |
              7. |                      (0.022)      (0.097)      (0.075)      (0.091) |
              8. |      w2             0.501***     0.858***    -1.066***    -0.636*** |
              9. |                      (0.025)      (0.085)      (0.080)      (0.098) |
             10. |      w3             0.109***     1.232***    -1.109***    -0.975*** |
             11. |                      (0.016)      (0.262)      (0.159)      (0.161) |
             12. |      -------------------------------------------------------------- |
             13. |                                    * p<0.05, ** p<0.01, *** p<0.001 |
             14. |                              UNCOMPENSATED CROSS-PRICE ELASTICITIES |
             15. |                   ------------------------------------------------- |
             16. |                                        P1           P2           P3 |
             17. |                                      b/se         b/se         b/se |
             18. |                   ------------------------------------------------- |
             19. |                      w1            -0.997***     0.136        0.004 |
             20. |                                   (0.075)      (0.089)      (0.059) |
             21. |                      w2             0.000       -1.066***     0.020 |
             22. |                                   (0.067)      (0.080)      (0.052) |
             23. |                   w3            -0.013       -0.185       -1.109*** |
             24. |                                   (0.204)      (0.239)      (0.159) |
             25. |                   ------------------------------------------------- |
             26. |                                    * p<0.05, ** p<0.01, *** p<0.001 |
             27. |                                COMPENSATED CROSS-PRICE ELASTICITIES |
             28. |                   ------------------------------------------------- |
             29. |                                        P1           P2           P3 |
             30. |                                      b/se         b/se         b/se |
             31. |                   ------------------------------------------------- |
             32. |                     w1            -0.561***     0.696***     0.126* |
             33. |                                   (0.091)      (0.113)      (0.062) |
             34. |                     w2             0.335***    -0.636***     0.114* |
             35. |                                   (0.080)      (0.098)      (0.053) |
             36. |                   w3             0.468        0.432       -0.975*** |
             37. |                                   (0.242)      (0.287)      (0.161) |
             38. |                   ------------------------------------------------- |
             39. |                                    * p<0.05, ** p<0.01, *** p<0.001 |
             40. |                                                                   . |
                 +---------------------------------------------------------------------+
            
            .

            Comment


            • #7
              Thank you Andrew, for these insights. I will make do with the options you have provided until any other option becomes available.
              I'm grateful for your time and efforts!

              Comment


              • #8
                Hey guys, I am wondering if there is an option for generating variables from the output or storing the elasticity estimates in any other way for further computation of uncompensated elasticities. Since I have quite a few estimates, copying them by hand appears very time-consuming and also prone for errors. If I understand you're previous posts correctly, exporting the estimates to excel and then appending the new dataset to the old one is the only real option so far?

                Best regards and happy new year!
                Julian

                Comment


                • #9
                  If you use the command frequently, you could modify the ado to allow it to output these estimates or ask the authors to do so. Otherwise, you don't have any other choices as the command leaves behind nothing except what you see on the screen.
                  Last edited by Andrew Musau; 03 Jan 2023, 00:36.

                  Comment


                  • #10
                    I am afraid modifying goes beyond my abilities, but thanks for clarifying!

                    Comment


                    • #11
                      Dear Statalisters, I use the same way to run AIDS model. After I ran aidsills, I want to use aidsills_elas to get elasticities. But it told me "last estimation results not found, nothing to store" even if I use est store before aidsills_elas. How can I solve this problem?

                      Thank you so much for your help in advance!

                      Comment

                      Working...
                      X