Announcement

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

  • loop over the panel IDs to use quantile regressions xtqreg

    Hi,

    I am running quantile regression for panel of 260 firms for period of 15 years. The general regression code xtqreg y x, gives an aggregate estimation of the entire data with all the panels. However, I want to run this regression for the individual panel IDs and don't find any way around. Joao Silvia suggested to ask Stata experts, how can I do a loop over the panel IDs to get the estimates of the regression for the individual panel IDs?


    Best Regards

  • #2
    Assuming you want to save the coefficient of x and its standard error as results in your data set, the simplest approach is this:

    Code:
    capture program drop one_id
    program define one_id
        qreg y x
        gen coeff = _b[x]
        gen se = _se[x]
        exit
    end
    
    runby one_id, by(ID) status
    Notes:

    1. -runby- is written by Robert Picard and me; it is available from SSC.

    2. Note that in program one_id I use qreg, not -xtqreg-. This is because -runby- will process this data one panel at a time. So when one_id is running, there is no longer any panel structure: only one panel is available.

    3. I am assuming the the variable ID identifies panels, and that these panels are the same panels you originally used when you -xtset- your data before running -xtqreg-. If this is not true, post back with an explanation and also use the -dataex- command to show example data.

    Comment


    • #3
      Dear Clyde,

      Thanks for your support. I am pasting the output that I am getting after running the code above:

      elapsed ----------- by-groups ---------- ------- observations ------ time
      time count errors no-data processed saved remaining
      ------------------------------------------------------------------------------------
      00:00:01 25 25 0 3,907 0 00:00:09
      00:00:02 69 69 0 10,365 0 00:00:05
      00:00:03 110 110 0 16,321 0 00:00:04
      00:00:04 152 152 0 21,571 0 00:00:03
      (now reporting every 5 seconds)
      00:00:07 262 262 0 38,101 0 00:00:00

      --------------------------------------
      Number of by-groups = 262
      by-groups with errors = 262
      by-groups with no data = 0
      Observations processed = 38,101
      Observations saved = 0
      --------------------------------------


      And when I browse, all the data and variables are gone, its a blank doc with no data. what does this mean? Moreover, I am not sure how meaningful are the results in the output window. they are just the count of observations and errors. I wanted to have the coefficients of all the individual panels through running quantile regression, which I dont's see and find out how to extract them.

      Best Regards

      Comment


      • #4
        In order to troubleshoot this, I need a sample of your data. (The code runs with no errors and produces correct results on the grunfeld.dta set provided by StataCorp with suitable renaming of variables, so there is something different about your data.) Use the -dataex- command to show an excerpt from your Stata data set. Be sure that the excerpt you show includes several different IDs and all of the variables that you use in your -xtqreg- (or, with my code, -qreg-) command.

        If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.


        Comment


        • #5
          Hi Clyde,

          I tried but I am not able to used Dataex with this large T data for each panel ID. I tried to generate random data out of the sample using randomtag, but it would give an error syntax saying type mismatch after the first code, to generate pick

          . randomtag if length(y_var) == 4, count(10) gen(pick)

          . dataex y_var x_var if pick

          thus I am not able to depict all the observations for atleast 2 or 3 panels using dataex, that's why I copied the data as below:
          Time FI_n Xi(y) L_MTbills L_MktR L_EV
          2011m3 2 1399.921 0 -5.670 4.609
          2011m4 2 1469.539 0 -2.904 4.015
          2011m5 2 1469.539 0.700 3.528 3.587
          2011m6 2 1472.498 0.840 -2.225 3.725
          2011m7 2 1538.159 0 -2.645 3.623
          2011m8 2 1538.159 1 -2.959 3.536
          2011m9 2 1541.468 0.930 -4.049 3.558
          2011m10 2 1615.177 0 0.719 3.441
          2011m11 2 1615.177 0.920 1.472 3.294
          2011m12 2 1615.177 0 -1.841 3.307
          2012m1 2 2053.130 0 0.045 3.306
          2012m2 2 2053.130 0.720 0.940 3.054
          2012m3 2 2053.130 0 4.299 3.007
          2012m4 2 2217.788 0 0.620 3.184
          2012m5 2 2217.788 0.760 3.249 2.677
          2012m6 2 2217.788 . -2.783 2.746
          2012m7 2 792.354 . -6.756 2.770
          2012m8 2 792.354 . -1.196 3.082
          2012m9 2 792.354 . 2.455 2.874
          2012m10 2 787.717 . 2.028 2.932
          2012m11 2 355.369 . -3.673 2.970
          2012m12 2 654.850 . 3.023 3.015
          2013m1 2 865.750 . -0.163 3.123
          2013m2 2 1093.095 . 5.105 2.915
          2013m3 2 1073.190 . 3.437 3.083
          2013m4 2 1103.127 . 3.915 3.078
          2013m5 2 919.176 . 10.028 3.148
          2013m6 2 1017.167 . 11.072 3.705
          2013m7 2 1083.820 . -6.568 4.199
          2013m8 2 906.396 . 3.754 4.387
          2013m9 2 936.887 . -5.575 4.414
          2013m10 2 1109.634 . 1.746 4.663
          2013m11 2 929.986 . 2.284 4.616
          2013m12 2 969.215 . -2.046 4.611
          2014m1 2 805.993 . -3.078 4.669
          2014m2 2 780.052 . 2.696 4.707
          2014m3 2 761.091 . -0.816 4.721
          2014m4 2 752.463 . -1.571 4.710
          2014m5 2 655.990 . -2.205 4.673
          2014m6 2 589.394 . -1.586 4.410
          2014m7 2 673.029 . -4.483 4.421
          2014m8 2 729.991 . 2.261 4.565
          2014m9 2 720.554 . 4.116 4.568
          2014m10 2 665.440 . 2.538 4.507
          2014m11 2 598.092 . -3.470 4.498
          2014m12 2 534.727 . -8.631 4.598
          2015m1 2 567.922 . -3.268 4.931
          2015m2 2 558.627 . 0.558 4.939
          2015m3 2 491.337 . 0.443 4.865
          2015m4 2 516.265 . -4.952 4.313
          2015m5 2 474.058 . 1.494 3.543
          2015m6 2 465.644 . -1.335 3.382
          2015m7 2 449.315 . -1.433 3.218
          2015m8 2 389.505 . 0.815 3.063
          2015m9 2 362.365 . -7.178 3.031
          2015m10 2 352.028 . -1.639 3.211
          2015m11 2 387.508 . 0.859 3.208
          2015m12 2 351.798 . 0.466 3.220
          2016m1 2 322.062 . -3.280 3.124
          2016m2 2 321.063 . -9.338 3.149
          2016m3 2 300.825 . 1.800 3.573
          2016m4 2 302.035 . 0.409 3.651
          2016m5 2 282.030 . 3.071 3.677
          2016m6 2 243.787 . 0.158 3.738
          2016m7 2 250.284 . -0.664 3.672
          2016m8 2 231.223 . 1.598 3.475
          2016m9 2 227.958 . -0.576 3.429
          2016m10 2 216.230 . -0.394 3.406
          2016m11 2 199.837 . 0.050 3.001
          2016m12 2 240.195 . 2.800 2.966
          2017m1 2 392.783 . 3.427 3.054
          2017m2 2 348.468 . 17.278 3.174
          2017m3 2 330.129 . -0.722 4.836
          2017m4 2 348.850 . 3.567 4.835
          2017m5 2 308.723 . -2.688 4.870
          2017m6 2 300.169 . -0.846 4.901
          2017m7 2 330.785 . -0.333 4.907
          2017m8 2 325.953 . 1.305 4.614
          2017m9 2 321.889 . 0.589 4.586
          2017m10 2 293.353 . -3.130 4.587
          2017m11 2 242.059 . -2.515 4.663
          2017m12 2 235.942 . -4.994 4.635
          2018m1 2 272.515 . 3.356 4.266
          2018m2 2 240.836 . 4.274 4.295
          2018m3 2 208.025 . 1.263 4.351
          2018m4 2 204.157 . -2.080 4.329
          2018m5 2 211.528 . -32.796 4.377
          2018m6 2 202.495 . -1.861 8.425
          2018m7 2 213.607 . 4.467 8.416
          2018m8 2 264.525 . 7.692 8.487
          2018m9 2 249.940 . -0.666 8.663
          2018m10 2 216.116 . 1.548 8.664
          2018m11 2 244.817 . -2.075 8.648
          2018m12 2 249.433 . 1.585 8.618
          2019m1 2 325.179 . -0.953 7.682
          2019m2 2 329.299 . 3.043 7.681
          2019m3 2 344.103 . 0.955 7.667
          2019m4 2 333.627 . 8.806 7.672
          2019m5 2 289.573 . 1.005 7.952
          2019m6 2 310.557 . 3.172 7.959
          2019m7 2 379.147 . 2.136 7.989
          2019m8 2 391.923 . 5.596 8.006
          2005m4 3 127.245 0 15.468 3.459
          2005m5 3 123.800 0 9.475 4.256
          2005m6 3 114.818 0 -4.145 4.111
          2005m7 3 188.646 0 5.979 4.462
          2005m8 3 196.787 0 1.820 4.453
          2005m9 3 226.247 0 7.193 4.231
          2005m10 3 423.601 0 5.949 4.267
          2005m11 3 410.346 0 11.414 4.294
          2005m12 3 410.163 0 3.415 4.582
          2006m1 3 286.244 0 -3.638 4.531
          2006m2 3 243.892 0 3.525 4.782
          2006m3 3 315.259 0 -2.674 4.349
          2006m4 3 400.426 0 -15.387 4.559
          2006m5 3 365.981 0 3.361 6.112
          2006m6 3 330.578 0 -3.119 6.113
          2006m7 3 397.946 0 0.815 6.237
          2006m8 3 372.446 0 -5.920 6.239
          2006m9 3 377.925 0 2.545 6.485
          2006m10 3 283.294 0 5.069 6.482
          2006m11 3 293.269 0 2.837 6.504
          2006m12 3 283.235 0 -7.028 6.497
          2007m1 3 254.011 0 3.150 6.790
          2007m2 3 239.677 0 -3.596 6.786
          2007m3 3 284.697 0 0.419 6.148
          2007m4 3 300.458 0 4.698 5.846
          2007m5 3 341.561 0 4.674 5.812
          2007m6 3 378.400 0 7.016 5.765
          2007m7 3 356.199 0 5.441 5.910
          2007m8 3 414.115 0 3.390 5.835
          2007m9 3 373.504 0 1.079 5.758
          2007m10 3 323.737 0 1.274 5.262
          2007m11 3 308.236 0 -0.638 5.224
          2007m12 3 341.313 0 -5.763 5.153
          2008m1 3 313.278 0 4.120 5.273
          2008m2 3 474.994 0 7.224 5.303
          2008m3 3 484.543 0 3.708 4.171
          2008m4 3 420.665 0 1.968 4.180
          2008m5 3 421.700 0 2.782 4.055
          2008m6 3 383.516 0 2.177 4.057
          2008m7 3 358.284 0 2.899 3.678
          2008m8 3 287.105 0 -3.146 3.681
          2008m9 3 233.982 0 -3.608 3.784
          2008m10 3 239.454 0 -11.796 3.943
          2008m11 3 207.342 0 -27.122 4.520
          2008m12 3 246.320 0 -9.803 7.524
          2009m1 3 209.569 0 -13.137 7.772
          2009m2 3 235.872 0 -14.020 8.227
          2009m3 3 291.180 0 -4.845 8.568
          2009m4 3 334.400 0 4.560 8.461
          2009m5 3 346.066 1.190 11.362 8.348
          2009m6 3 315.585 0.720 7.556 8.701
          2009m7 3 311.061 0 -0.859 8.871
          2009m8 3 327.981 0 -5.087 8.849
          2009m9 3 350.421 0 3.012 8.839
          2009m10 3 310.032 0 -1.233 8.907
          2009m11 3 307.854 0.960 -6.198 8.872
          2009m12 3 290.303 0.800 -5.797 8.808
          2010m1 3 270.171 0 1.027 8.562
          2010m2 3 246.901 0.850 0.285 8.480
          2010m3 3 251.524 0.780 4.909 8.439
          2010m4 3 230.153 0 2.076 8.523
          2010m5 3 204.730 0.670 -3.158 8.520
          2010m6 3 176.639 0.600 -8.573 8.413
          2010m7 3 192.908 0 -2.364 8.484
          2010m8 3 203.097 0.590 1.693 8.488
          2010m9 3 195.306 0.530 0.505 8.354
          2010m10 3 200.562 0 4.336 6.402
          2010m11 3 198.771 0.550 1.123 6.261
          2010m12 3 210.318 0.510 -2.478 5.664
          2011m1 3 190.060 0 0.932 4.818
          2011m2 3 175.159 0.670 -1.394 4.692
          2011m3 3 182.389 0 -5.670 4.609
          2011m4 3 177.288 0 -2.904 4.015
          2011m5 3 163.713 0.700 3.528 3.587
          2011m6 3 164.426 0.840 -2.225 3.725
          2011m7 3 150.275 0 -2.645 3.623
          2011m8 3 150.557 1 -2.959 3.536
          2011m9 3 146.115 0.930 -4.049 3.558
          2011m10 3 138.592 0 0.719 3.441
          2011m11 3 132.747 0.920 1.472 3.294
          2011m12 3 135.738 0 -1.841 3.307
          2012m1 3 142.828 0 0.045 3.306
          2012m2 3 166.873 0.720 0.940 3.054
          2012m3 3 169.428 0 4.299 3.007
          2012m4 3 207.998 0 0.620 3.184
          2012m5 3 178.505 0.760 3.249 2.677
          2012m6 3 175.387 . -2.783 2.746
          2012m7 3 199.794 . -6.756 2.770
          2012m8 3 198.437 . -1.196 3.082
          2012m9 3 186.788 . 2.455 2.874
          2012m10 3 166.131 . 2.028 2.932
          2012m11 3 161.935 . -3.673 2.970
          2012m12 3 174.920 . 3.023 3.015
          2013m1 3 220.187 . -0.163 3.123
          2013m2 3 218.947 . 5.105 2.915
          2013m3 3 211.413 . 3.437 3.083
          2013m4 3 248.997 . 3.915 3.078
          2013m5 3 236.498 . 10.028 3.148
          2013m6 3 250.086 . 11.072 3.705
          2013m7 3 225.984 . -6.568 4.199
          2013m8 3 211.463 . 3.754 4.387
          2013m9 3 224.919 . -5.575 4.414
          2013m10 3 205.671 . 1.746 4.663
          2013m11 3 195.289 . 2.284 4.616
          2013m12 3 222.012 . -2.046 4.611
          2014m1 3 189.979 . -3.078 4.669
          2014m2 3 180.276 . 2.696 4.707
          2014m3 3 192.405 . -0.816 4.721
          2014m4 3 179.375 . -1.571 4.710
          2014m5 3 171.741 . -2.205 4.673
          2014m6 3 174.767 . -1.586 4.410
          2014m7 3 190.678 . -4.483 4.421
          2014m8 3 188.317 . 2.261 4.565
          2014m9 3 183.740 . 4.116 4.568
          2014m10 3 165.995 . 2.538 4.507
          2014m11 3 160.971 . -3.470 4.498
          2014m12 3 172.458 . -8.631 4.598
          2015m1 3 196.668 . -3.268 4.931
          2015m2 3 166.319 . 0.558 4.939
          2015m3 3 178.428 . 0.443 4.865
          2015m4 3 176.216 . -4.952 4.313
          2015m5 3 162.692 . 1.494 3.543
          2015m6 3 167.969 . -1.335 3.382
          2015m7 3 139.665 . -1.433 3.218
          2015m8 3 153.123 . 0.815 3.063
          2015m9 3 154.570 . -7.178 3.031
          2015m10 3 153.199 . -1.639 3.211
          2015m11 3 148.099 . 0.859 3.208
          2015m12 3 128.959 . 0.466 3.220
          2016m1 3 127.170 . -3.280 3.124
          2016m2 3 126.703 . -9.338 3.149
          2016m3 3 128.796 . 1.800 3.573
          2016m4 3 117.123 . 0.409 3.651
          2016m5 3 113.430 . 3.071 3.677
          2016m6 3 122.965 . 0.158 3.738
          2016m7 3 111.032 . -0.664 3.672
          2016m8 3 109.408 . 1.598 3.475
          2016m9 3 106.934 . -0.576 3.429
          2016m10 3 111.491 . -0.394 3.406
          2016m11 3 116.664 . 0.050 3.001
          2016m12 3 148.003 . 2.800 2.966
          2017m1 3 128.165 . 3.427 3.054
          2017m2 3 148.711 . 17.278 3.174
          2017m3 3 149.019 . -0.722 4.836
          2017m4 3 135.809 . 3.567 4.835
          2017m5 3 143.771 . -2.688 4.870
          2017m6 3 140.023 . -0.846 4.901
          2017m7 3 139.212 . -0.333 4.907
          2017m8 3 141.249 . 1.305 4.614
          Please let me know if this data isn't helpful. If you think it is possible to copy a large sample including more IDs, please let me know.

          Best Regards
          Last edited by Aamina Khurraa; 28 Sep 2019, 08:34.

          Comment


          • #6
            Clyde Schechter

            Please see the above post.

            Thanks

            Comment


            • #7
              OK. -dataex- has a -count()- option. Had you specified that with a large enough number, you would have been able to get -dataex- output of a sufficient number of observations. Nevertheless, I have worked with what you show. It isn't clear how this data relates to what you describe in number 1. There is no variable named ID, nor any named x, nor y. I'm going to guess that fi_n is the ID variable and that y is l_mktr and x is xiy. With those assumptions, I cannot replicate your problem--this runs just fine for me and produces the expected output:

              Code:
              . * Example generated by -dataex-. To install: ssc install dataex
              . clear
              
              . input int time byte fi_n float(xiy l_mtbills l_mktr l_ev)
              
                       time      fi_n        xiy  l_mtbills     l_mktr       l_ev
                1. 614 2 1399.921    0   -5.67 4.609
                2. 615 2 1469.539    0  -2.904 4.015
                3. 616 2 1469.539   .7   3.528 3.587
                4. 617 2 1472.498  .84  -2.225 3.725
                5. 618 2 1538.159    0  -2.645 3.623
                6. 619 2 1538.159    1  -2.959 3.536
                7. 620 2 1541.468  .93  -4.049 3.558
                8. 621 2 1615.177    0    .719 3.441
                9. 622 2 1615.177  .92   1.472 3.294
               10. 623 2 1615.177    0  -1.841 3.307
               11. 624 2  2053.13    0    .045 3.306
               12. 625 2  2053.13  .72     .94 3.054
               13. 626 2  2053.13    0   4.299 3.007
               14. 627 2 2217.788    0     .62 3.184
               15. 628 2 2217.788  .76   3.249 2.677
               16. 629 2 2217.788    .  -2.783 2.746
               17. 630 2  792.354    .  -6.756  2.77
               18. 631 2  792.354    .  -1.196 3.082
               19. 632 2  792.354    .   2.455 2.874
               20. 633 2  787.717    .   2.028 2.932
               21. 634 2  355.369    .  -3.673  2.97
               22. 635 2   654.85    .   3.023 3.015
               23. 636 2   865.75    .   -.163 3.123
               24. 637 2 1093.095    .   5.105 2.915
               25. 638 2  1073.19    .   3.437 3.083
               26. 639 2 1103.127    .   3.915 3.078
               27. 640 2  919.176    .  10.028 3.148
               28. 641 2 1017.167    .  11.072 3.705
               29. 642 2  1083.82    .  -6.568 4.199
               30. 643 2  906.396    .   3.754 4.387
               31. 644 2  936.887    .  -5.575 4.414
               32. 645 2 1109.634    .   1.746 4.663
               33. 646 2  929.986    .   2.284 4.616
               34. 647 2  969.215    .  -2.046 4.611
               35. 648 2  805.993    .  -3.078 4.669
               36. 649 2  780.052    .   2.696 4.707
               37. 650 2  761.091    .   -.816 4.721
               38. 651 2  752.463    .  -1.571  4.71
               39. 652 2   655.99    .  -2.205 4.673
               40. 653 2  589.394    .  -1.586  4.41
               41. 654 2  673.029    .  -4.483 4.421
               42. 655 2  729.991    .   2.261 4.565
               43. 656 2  720.554    .   4.116 4.568
               44. 657 2   665.44    .   2.538 4.507
               45. 658 2  598.092    .   -3.47 4.498
               46. 659 2  534.727    .  -8.631 4.598
               47. 660 2  567.922    .  -3.268 4.931
               48. 661 2  558.627    .    .558 4.939
               49. 662 2  491.337    .    .443 4.865
               50. 663 2  516.265    .  -4.952 4.313
               51. 664 2  474.058    .   1.494 3.543
               52. 665 2  465.644    .  -1.335 3.382
               53. 666 2  449.315    .  -1.433 3.218
               54. 667 2  389.505    .    .815 3.063
               55. 668 2  362.365    .  -7.178 3.031
               56. 669 2  352.028    .  -1.639 3.211
               57. 670 2  387.508    .    .859 3.208
               58. 671 2  351.798    .    .466  3.22
               59. 672 2  322.062    .   -3.28 3.124
               60. 673 2  321.063    .  -9.338 3.149
               61. 674 2  300.825    .     1.8 3.573
               62. 675 2  302.035    .    .409 3.651
               63. 676 2   282.03    .   3.071 3.677
               64. 677 2  243.787    .    .158 3.738
               65. 678 2  250.284    .   -.664 3.672
               66. 679 2  231.223    .   1.598 3.475
               67. 680 2  227.958    .   -.576 3.429
               68. 681 2   216.23    .   -.394 3.406
               69. 682 2  199.837    .     .05 3.001
               70. 683 2  240.195    .     2.8 2.966
               71. 684 2  392.783    .   3.427 3.054
               72. 685 2  348.468    .  17.278 3.174
               73. 686 2  330.129    .   -.722 4.836
               74. 687 2   348.85    .   3.567 4.835
               75. 688 2  308.723    .  -2.688  4.87
               76. 689 2  300.169    .   -.846 4.901
               77. 690 2  330.785    .   -.333 4.907
               78. 691 2  325.953    .   1.305 4.614
               79. 692 2  321.889    .    .589 4.586
               80. 693 2  293.353    .   -3.13 4.587
               81. 694 2  242.059    .  -2.515 4.663
               82. 695 2  235.942    .  -4.994 4.635
               83. 696 2  272.515    .   3.356 4.266
               84. 697 2  240.836    .   4.274 4.295
               85. 698 2  208.025    .   1.263 4.351
               86. 699 2  204.157    .   -2.08 4.329
               87. 700 2  211.528    . -32.796 4.377
               88. 701 2  202.495    .  -1.861 8.425
               89. 702 2  213.607    .   4.467 8.416
               90. 703 2  264.525    .   7.692 8.487
               91. 704 2   249.94    .   -.666 8.663
               92. 705 2  216.116    .   1.548 8.664
               93. 706 2  244.817    .  -2.075 8.648
               94. 707 2  249.433    .   1.585 8.618
               95. 708 2  325.179    .   -.953 7.682
               96. 709 2  329.299    .   3.043 7.681
               97. 710 2  344.103    .    .955 7.667
               98. 711 2  333.627    .   8.806 7.672
               99. 712 2  289.573    .   1.005 7.952
              100. 713 2  310.557    .   3.172 7.959
              101. 714 2  379.147    .   2.136 7.989
              102. 715 2  391.923    .   5.596 8.006
              103. 543 3  127.245    0  15.468 3.459
              104. 544 3    123.8    0   9.475 4.256
              105. 545 3  114.818    0  -4.145 4.111
              106. 546 3  188.646    0   5.979 4.462
              107. 547 3  196.787    0    1.82 4.453
              108. 548 3  226.247    0   7.193 4.231
              109. 549 3  423.601    0   5.949 4.267
              110. 550 3  410.346    0  11.414 4.294
              111. 551 3  410.163    0   3.415 4.582
              112. 552 3  286.244    0  -3.638 4.531
              113. 553 3  243.892    0   3.525 4.782
              114. 554 3  315.259    0  -2.674 4.349
              115. 555 3  400.426    0 -15.387 4.559
              116. 556 3  365.981    0   3.361 6.112
              117. 557 3  330.578    0  -3.119 6.113
              118. 558 3  397.946    0    .815 6.237
              119. 559 3  372.446    0   -5.92 6.239
              120. 560 3  377.925    0   2.545 6.485
              121. 561 3  283.294    0   5.069 6.482
              122. 562 3  293.269    0   2.837 6.504
              123. 563 3  283.235    0  -7.028 6.497
              124. 564 3  254.011    0    3.15  6.79
              125. 565 3  239.677    0  -3.596 6.786
              126. 566 3  284.697    0    .419 6.148
              127. 567 3  300.458    0   4.698 5.846
              128. 568 3  341.561    0   4.674 5.812
              129. 569 3    378.4    0   7.016 5.765
              130. 570 3  356.199    0   5.441  5.91
              131. 571 3  414.115    0    3.39 5.835
              132. 572 3  373.504    0   1.079 5.758
              133. 573 3  323.737    0   1.274 5.262
              134. 574 3  308.236    0   -.638 5.224
              135. 575 3  341.313    0  -5.763 5.153
              136. 576 3  313.278    0    4.12 5.273
              137. 577 3  474.994    0   7.224 5.303
              138. 578 3  484.543    0   3.708 4.171
              139. 579 3  420.665    0   1.968  4.18
              140. 580 3    421.7    0   2.782 4.055
              141. 581 3  383.516    0   2.177 4.057
              142. 582 3  358.284    0   2.899 3.678
              143. 583 3  287.105    0  -3.146 3.681
              144. 584 3  233.982    0  -3.608 3.784
              145. 585 3  239.454    0 -11.796 3.943
              146. 586 3  207.342    0 -27.122  4.52
              147. 587 3   246.32    0  -9.803 7.524
              148. 588 3  209.569    0 -13.137 7.772
              149. 589 3  235.872    0  -14.02 8.227
              150. 590 3   291.18    0  -4.845 8.568
              151. 591 3    334.4    0    4.56 8.461
              152. 592 3  346.066 1.19  11.362 8.348
              153. 593 3  315.585  .72   7.556 8.701
              154. 594 3  311.061    0   -.859 8.871
              155. 595 3  327.981    0  -5.087 8.849
              156. 596 3  350.421    0   3.012 8.839
              157. 597 3  310.032    0  -1.233 8.907
              158. 598 3  307.854  .96  -6.198 8.872
              159. 599 3  290.303   .8  -5.797 8.808
              160. 600 3  270.171    0   1.027 8.562
              161. 601 3  246.901  .85    .285  8.48
              162. 602 3  251.524  .78   4.909 8.439
              163. 603 3  230.153    0   2.076 8.523
              164. 604 3   204.73  .67  -3.158  8.52
              165. 605 3  176.639   .6  -8.573 8.413
              166. 606 3  192.908    0  -2.364 8.484
              167. 607 3  203.097  .59   1.693 8.488
              168. 608 3  195.306  .53    .505 8.354
              169. 609 3  200.562    0   4.336 6.402
              170. 610 3  198.771  .55   1.123 6.261
              171. 611 3  210.318  .51  -2.478 5.664
              172. 612 3   190.06    0    .932 4.818
              173. 613 3  175.159  .67  -1.394 4.692
              174. 614 3  182.389    0   -5.67 4.609
              175. 615 3  177.288    0  -2.904 4.015
              176. 616 3  163.713   .7   3.528 3.587
              177. 617 3  164.426  .84  -2.225 3.725
              178. 618 3  150.275    0  -2.645 3.623
              179. 619 3  150.557    1  -2.959 3.536
              180. 620 3  146.115  .93  -4.049 3.558
              181. 621 3  138.592    0    .719 3.441
              182. 622 3  132.747  .92   1.472 3.294
              183. 623 3  135.738    0  -1.841 3.307
              184. 624 3  142.828    0    .045 3.306
              185. 625 3  166.873  .72     .94 3.054
              186. 626 3  169.428    0   4.299 3.007
              187. 627 3  207.998    0     .62 3.184
              188. 628 3  178.505  .76   3.249 2.677
              189. 629 3  175.387    .  -2.783 2.746
              190. 630 3  199.794    .  -6.756  2.77
              191. 631 3  198.437    .  -1.196 3.082
              192. 632 3  186.788    .   2.455 2.874
              193. 633 3  166.131    .   2.028 2.932
              194. 634 3  161.935    .  -3.673  2.97
              195. 635 3   174.92    .   3.023 3.015
              196. 636 3  220.187    .   -.163 3.123
              197. 637 3  218.947    .   5.105 2.915
              198. 638 3  211.413    .   3.437 3.083
              199. 639 3  248.997    .   3.915 3.078
              200. 640 3  236.498    .  10.028 3.148
              201. 641 3  250.086    .  11.072 3.705
              202. 642 3  225.984    .  -6.568 4.199
              203. 643 3  211.463    .   3.754 4.387
              204. 644 3  224.919    .  -5.575 4.414
              205. 645 3  205.671    .   1.746 4.663
              206. 646 3  195.289    .   2.284 4.616
              207. 647 3  222.012    .  -2.046 4.611
              208. 648 3  189.979    .  -3.078 4.669
              209. 649 3  180.276    .   2.696 4.707
              210. 650 3  192.405    .   -.816 4.721
              211. 651 3  179.375    .  -1.571  4.71
              212. 652 3  171.741    .  -2.205 4.673
              213. 653 3  174.767    .  -1.586  4.41
              214. 654 3  190.678    .  -4.483 4.421
              215. 655 3  188.317    .   2.261 4.565
              216. 656 3   183.74    .   4.116 4.568
              217. 657 3  165.995    .   2.538 4.507
              218. 658 3  160.971    .   -3.47 4.498
              219. 659 3  172.458    .  -8.631 4.598
              220. 660 3  196.668    .  -3.268 4.931
              221. 661 3  166.319    .    .558 4.939
              222. 662 3  178.428    .    .443 4.865
              223. 663 3  176.216    .  -4.952 4.313
              224. 664 3  162.692    .   1.494 3.543
              225. 665 3  167.969    .  -1.335 3.382
              226. 666 3  139.665    .  -1.433 3.218
              227. 667 3  153.123    .    .815 3.063
              228. 668 3   154.57    .  -7.178 3.031
              229. 669 3  153.199    .  -1.639 3.211
              230. 670 3  148.099    .    .859 3.208
              231. 671 3  128.959    .    .466  3.22
              232. 672 3   127.17    .   -3.28 3.124
              233. 673 3  126.703    .  -9.338 3.149
              234. 674 3  128.796    .     1.8 3.573
              235. 675 3  117.123    .    .409 3.651
              236. 676 3   113.43    .   3.071 3.677
              237. 677 3  122.965    .    .158 3.738
              238. 678 3  111.032    .   -.664 3.672
              239. 679 3  109.408    .   1.598 3.475
              240. 680 3  106.934    .   -.576 3.429
              241. 681 3  111.491    .   -.394 3.406
              242. 682 3  116.664    .     .05 3.001
              243. 683 3  148.003    .     2.8 2.966
              244. 684 3  128.165    .   3.427 3.054
              245. 685 3  148.711    .  17.278 3.174
              246. 686 3  149.019    .   -.722 4.836
              247. 687 3  135.809    .   3.567 4.835
              248. 688 3  143.771    .  -2.688  4.87
              249. 689 3  140.023    .   -.846 4.901
              250. 690 3  139.212    .   -.333 4.907
              251. 691 3  141.249    .   1.305 4.614
              252. end
              
              . format %tm time
              
              . 
              . capture program drop one_id
              
              . program define one_id
                1.     qreg l_mktr xiy
                2.     gen coeff = _b[xiy]
                3.     gen se = _se[xiy]
                4.     exit
                5. end
              
              . 
              . runby one_id, by(fi_n) status verbose
              Iteration  1:  WLS sum of weighted deviations =  165.68546
              
              Iteration  1: sum of abs. weighted deviations =  165.28218
              Iteration  2: sum of abs. weighted deviations =  165.00504
              
              Median regression                                   Number of obs =        102
                Raw sum of deviations    165.1 (about .40900001)
                Min sum of deviations  165.005                    Pseudo R2     =     0.0006
              
              ------------------------------------------------------------------------------
                    l_mktr |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
                       xiy |   .0001101   .0008328     0.13   0.895    -.0015422    .0017624
                     _cons |    .375734    .727378     0.52   0.607    -1.067363    1.818831
              ------------------------------------------------------------------------------
              Iteration  1:  WLS sum of weighted deviations =  284.41446
              
              Iteration  1: sum of abs. weighted deviations =  284.73163
              Iteration  2: sum of abs. weighted deviations =  280.75249
              Iteration  3: sum of abs. weighted deviations =  280.53192
              Iteration  4: sum of abs. weighted deviations =  280.52097
              
              Median regression                                   Number of obs =        149
                Raw sum of deviations  290.349 (about .505)
                Min sum of deviations  280.521                    Pseudo R2     =     0.0338
              
              ------------------------------------------------------------------------------
                    l_mktr |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
                       xiy |    .010507   .0046795     2.25   0.026     .0012593    .0197547
                     _cons |  -1.565437   1.137977    -1.38   0.171    -3.814346    .6834721
              ------------------------------------------------------------------------------
              
                elapsed ----------- by-groups ----------    ------- observations ------       time
                   time      count     errors    no-data        processed         saved  remaining
              ------------------------------------------------------------------------------------
               00:00:00          2          0          0              251           251   00:00:00
              
              --------------------------------------
              Number of by-groups    =             2
              by-groups with errors  =             0
              by-groups with no data =             0
              Observations processed =           251
              Observations saved     =           251
              --------------------------------------
              
              . 
              end of do-file
              
              . list in 1/5, noobs clean
              
                    time   fi_n        xiy   l_mtbi~s   l_mktr    l_ev      coeff         se  
                  2011m3      2   1399.921          0    -5.67   4.609   .0001101   .0008328  
                  2011m4      2   1469.539          0   -2.904   4.015   .0001101   .0008328  
                  2011m5      2   1469.539         .7    3.528   3.587   .0001101   .0008328  
                  2011m6      2   1472.498        .84   -2.225   3.725   .0001101   .0008328  
                  2011m7      2   1538.159          0   -2.645   3.623   .0001101   .0008328
              So I don't know what to tell you.

              Comment


              • #8
                Clyde Schechter

                Dear Clyde,

                I apologies for not telling you the variables specifications.

                FI_n is the panle ID, Xiy=y variable and all others are the X variables i.e. l_mtbi~s l_mktr l_ev

                Please also note that this is just a small part of my data but my IDs in total are 260. I am still trying again but not getting what you have shown here.

                Best
                Aamina

                Comment


                • #9
                  OK, what you are describing now is very different from your request in #1. You do not have a single predictor variable here, you have several. That means that the code in program one_id must be modified to store the coefficients and standard errors for each of those. I suspect that your problem is that you have not done that, or have done it incorrectly.

                  Code:
                  capture program drop one_id
                  
                  program define one_id
                      qreg xiy l_mtbills l_mktr l_ev
                      foreach v of varlist l_mtbills l_mktr l_ev {
                          gen coeff_`v' = _b[`v']
                          gen se_`v' = _se[`v']
                      }
                      exit
                  end
                  
                  
                  runby one_id, by(fi_n) status
                  This works with your example data and produces sensible-looking results.

                  If you are still getting a status report indicating that all by-groups contained errors (or that a substantial number of them did), then I recommend you add the -verbose- option to your -runby- command. That won't fix anything, but it will cause Stata to show you the group-by-group output. That output will include error messages that will show you what is going wrong inside program one_id when you run it with your data, and that will enable you to make corrections to the code or to your data as needed. Once you get it working, you can then take out the -verbose- option for a final production run that will not be cluttered with the output from each by-group.

                  Comment


                  • #10
                    Thank you so much Clyde Schechter ,

                    It works perfect in generating coeff and SE for all X variables now. Just to ask, is there a way we can extract those per ID in the data, as in the data view file, the same values are repeated for each time entity of each panel as it is a time panel data with T ranging Monthly from year 2000 to 2019. The output looks something like as below and it is only for Panel ID =1.

                    coeff_L_MktR se_L_MktR coeff_L_EV se_L_EV
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975
                    -261.4751 357.8233 5754.764 472.975

                    Another thing is that since it is a panel data, shouldn't I use xtqreg instead of qreg only? and do I need to mention fe(fixed effects) or re(random effects) with the regression codes here?

                    Also as I wan to do qreg at 0.05 lowest quantile, can I add q(0.05) to the above one_id code that you have metioned.

                    Thanks again in anticipation

                    Comment


                    • #11
                      Just to ask, is there a way we can extract those per ID in the data, as in the data view file
                      I don't understand what this means. You showed what you have (and it is what I expected you to have). But I don't understand from your explanation what you want instead.

                      Another thing is that since it is a panel data, shouldn't I use xtqreg instead of qreg only? and do I need to mention fe(fixed effects) or re(random effects) with the regression codes here?
                      No. What -runby- does is break the data up and run -qreg- on each panel one at a time. Within each panel there is no longer any panel structure, so you use qreg, not -xtqreg-. This is more analogous to doing -xtqreg, fe- than -re-, but it isn't the same as either because in -xtqreg- you are constraining every coefficient to be the same in every ID, whereas the very purpose of this analysis is to estimate separate coefficients in each ID.

                      Also as I wan to do qreg at 0.05 lowest quantile, can I add q(0.05) to the above one_id code that you have metioned.
                      Yes.

                      Comment


                      • #12
                        Thanks again Clyde for a wonderful explanation.

                        By the first part of the questions, I tried to mean was that when Coeff and Se variables are generated in the stata data file, the same values of the coeffs are repeated for every time unit(T) of say panel ID 1(like I showed in the data I pasted before), Is it possible to extract those Coeff and Se one for each panel may be in the form of a table.

                        Also, I tried to run the time invariant regression where the Y variable was the returns of all the panels in the system and X variable is only one Panel returns at a time. when I run the code:

                        qreg Y(all panels returns) X(returns of panel=1 or 2 or 3....)

                        There is no output and it says convergence not achieved and failed to compute vce. Also sometimes it says data is collinear, may be because X(panel1) is also a part of Y(X all panels). Can you see how to get around this? IS that I have to use syntax "fe" with qreg

                        Can you also mention if there is a code to run the entire data or total panels' return (Y) regression with the individual panel returns one by one(X1, X2...). Do I need to separately generate variables as R1, R2 .... for all the individual Panel's returns(X1, X2..) and then regress them with the total panels'returns(Y) or can this be done through some code?

                        Best Regards

                        Comment


                        • #13
                          By the first part of the questions, I tried to mean was that when Coeff and Se variables are generated in the stata data file, the same values of the coeffs are repeated for every time unit(T) of say panel ID 1(like I showed in the data I pasted before), Is it possible to extract those Coeff and Se one for each panel may be in the form of a table.
                          Code:
                          collapse b_* se_*, by(ID)
                          Also, I tried to run the time invariant regression where the Y variable was the returns of all the panels in the system and X variable is only one Panel returns at a time. when I run the code:

                          qreg Y(all panels returns) X(returns of panel=1 or 2 or 3....)

                          There is no output and it says convergence not achieved and failed to compute vce. Also sometimes it says data is collinear, may be because X(panel1) is also a part of Y(X all panels). Can you see how to get around this?
                          How is this new Y variable (all panel returns) calculated? Also, this would seem to require some different data structure from what you are working with. I don't really understand what you want to do here.

                          Comment


                          • #14
                            Thanks a million Clyde Schechter

                            The Y variable is not any new variable, but already existing in the dataset. It is actually the asset return of each panel for each time period.and I want to regress the whole system(all panels included) returns(Xi) with the individual panel returns(xi, for FI_n=1) where i represents individual panel(firms) in the data. Please have a look at this data below: FI_n is the panel ID and the Y variable is Xi, X variable is the Xi of the individual panel (1,2,3) at a time. That means regression would be:

                            qreg Xi Xi(if FI_n=1)

                            qreg Xi Xi(if FI_n=2) and so on for 260 Panel IDs.


                            Time FI_n Xi
                            2013m10 1 -.68829912
                            2013m11 1 -.65554559
                            2013m12 1 -.6428563
                            2014m1 1 -.49947822
                            2014m2 1 -.63309532
                            2014m3 1 -.53743768
                            2014m4 1 -.65272576
                            2014m5 1 -.65446103
                            2014m6 1 -.6711632
                            2014m7 1 -.70261526
                            2014m8 1 -.64925516
                            2014m9 1 -.61379027
                            2014m10 1 -.68233407
                            2014m11 1 -.65706396
                            2014m12 1 -.65619636
                            2015m1 1 -.65619636
                            2015m2 1 -.65619636
                            2015m3 1 -.65619636
                            2015m4 1 -.65619636
                            2015m5 1 -.65619636
                            2015m6 1 -.65619636
                            2015m7 1 -.65619636
                            2015m8 1 -.65619636
                            2015m9 1 -.65619636
                            2015m10 1 -.65619636
                            2015m11 1 -.65619636
                            2015m12 1 -.65619636
                            2016m1 1 -.65619636
                            2016m2 1 -.65619636
                            2016m3 1 -.65619636
                            2016m4 1 -.65619636
                            2016m5 1 -.65619636
                            2016m6 1 -.65619636
                            2016m7 1 -.65619636
                            2016m8 1 -.65619636
                            2016m9 1 -.65619636
                            2016m10 1 -.65619636
                            2016m11 1 -.65619636
                            2016m12 1 -.65619636
                            2017m1 1 -.65619636
                            2017m2 1 -.65619636
                            2017m3 1 -.53526855
                            2017m4 1 -.53483474
                            2017m5 1 -.53516006
                            2017m6 1 -.53516006
                            2017m7 1 -.53516006
                            2017m8 1 -.53516006
                            2017m9 1 -.53516006
                            2017m10 1 -.53516006
                            2017m11 1 -.53516006
                            2017m12 1 -.53516006
                            2018m1 1 -.53516006
                            2018m2 1 -.53516006
                            2018m3 1 -.53516006
                            2018m4 1 -.53516006
                            2018m5 1 -.53516006
                            2018m6 1 -.53516006
                            2018m7 1 -.53888303
                            2018m8 1 -.53888303
                            2018m9 1 -.21644539
                            2018m10 1 .86932051
                            2018m11 1 1.8060787
                            2018m12 1 1.8667576
                            2019m1 1 1.9795086
                            2019m2 1 1.9983363
                            2019m3 1 1.9778948
                            2019m4 1 1.9763885
                            2019m5 1 1.9914508
                            2019m6 1 1.7823019
                            2019m7 1 2.0497627
                            2019m8 1 2.2976427
                            2012m11 2 355.36917
                            2012m12 2 654.85046
                            2013m1 2 865.75024
                            2013m2 2 1093.0953
                            2013m3 2 1073.1897
                            2013m4 2 1103.1268
                            2013m5 2 919.17633
                            2013m6 2 1017.1666
                            2013m7 2 1083.8204
                            2013m8 2 906.39642
                            2013m9 2 936.88745
                            2013m10 2 1109.6343
                            2013m11 2 929.98602
                            2013m12 2 969.21454
                            2014m1 2 805.99261
                            2014m2 2 780.05219
                            2014m3 2 761.09082
                            2014m4 2 752.46313
                            2014m5 2 655.98969
                            2014m6 2 589.3941
                            2014m7 2 673.02863
                            2014m8 2 729.99103
                            2014m9 2 720.55396
                            2014m10 2 665.44006
                            2014m11 2 598.09229
                            2014m12 2 534.72717
                            2015m1 2 567.92194
                            2015m2 2 558.62708
                            2015m3 2 491.33698
                            2015m4 2 516.26483
                            2015m5 2 474.05835
                            2015m6 2 465.64438
                            2015m7 2 449.31503
                            2015m8 2 389.5047
                            2015m9 2 362.36499
                            2015m10 2 352.0278
                            2015m11 2 387.50766
                            2015m12 2 351.79791
                            2016m1 2 322.06165
                            2016m2 2 321.06311
                            2016m3 2 300.82455
                            2016m4 2 302.03534
                            2016m5 2 282.02972
                            2016m6 2 243.78677
                            2016m7 2 250.28363
                            2016m8 2 231.22293
                            2016m9 2 227.95763
                            2016m10 2 216.23006
                            2016m11 2 199.8372
                            2016m12 2 240.1955
                            2017m1 2 392.78323
                            2017m2 2 348.46765
                            2017m3 2 330.12857
                            2017m4 2 348.85031
                            2017m5 2 308.72275
                            2017m6 2 300.16937
                            2017m7 2 330.78461
                            2017m8 2 325.95261
                            2017m9 2 321.88885
                            2017m10 2 293.35306
                            2017m11 2 242.05925
                            2017m12 2 235.94232
                            2018m1 2 272.51468
                            2018m2 2 240.83572
                            2018m3 2 208.02515
                            2018m4 2 204.15651
                            2018m5 2 211.52809
                            2018m6 2 202.49466
                            2018m7 2 213.60698
                            2018m8 2 264.52454
                            2018m9 2 249.94032
                            2018m10 2 216.1156
                            2018m11 2 244.81712
                            2018m12 2 249.43275
                            2019m1 2 325.17941
                            2019m2 2 329.29874
                            2019m3 2 344.10272
                            2019m4 2 333.62732
                            2019m5 2 289.57346
                            2019m6 2 310.55719
                            2019m7 2 379.14719
                            2019m8 2 391.92252
                            2011m12 3 135.73845
                            2012m1 3 142.82813
                            2012m2 3 166.87296
                            2012m3 3 169.42847
                            2012m4 3 207.99799
                            2012m5 3 178.50516
                            2012m6 3 175.3868
                            2012m7 3 199.79358
                            2012m8 3 198.43716
                            2012m9 3 186.78813
                            2012m10 3 166.13101
                            2012m11 3 161.93526
                            2012m12 3 174.91965
                            2013m1 3 220.18668
                            2013m2 3 218.94662
                            2013m3 3 211.4133
                            2013m4 3 248.99706
                            2013m5 3 236.49826
                            2013m6 3 250.08646
                            2013m7 3 225.98436
                            2013m8 3 211.4628
                            2013m9 3 224.91881
                            2013m10 3 205.67104
                            2013m11 3 195.28877
                            2013m12 3 222.01204
                            2014m1 3 189.9785
                            2014m2 3 180.2758
                            2014m3 3 192.40457
                            2014m4 3 179.37495
                            2014m5 3 171.74084
                            2014m6 3 174.76704
                            2014m7 3 190.67757
                            2014m8 3 188.31688
                            2014m9 3 183.73953
                            2014m10 3 165.9951
                            2014m11 3 160.9707
                            2014m12 3 172.45792
                            2015m1 3 196.66788
                            2015m2 3 166.31879
                            2015m3 3 178.42822
                            2015m4 3 176.21552
                            2015m5 3 162.69159
                            2015m6 3 167.96936
                            2015m7 3 139.6649
                            2015m8 3 153.12274
                            2015m9 3 154.56984
                            2015m10 3 153.19868
                            2015m11 3 148.0993
                            2015m12 3 128.95886
                            2016m1 3 127.1698
                            2016m2 3 126.70283
                            2016m3 3 128.79564
                            2016m4 3 117.12334
                            2016m5 3 113.43034
                            2016m6 3 122.96464
                            2016m7 3 111.0322
                            2016m8 3 109.40765
                            2016m9 3 106.93421
                            2016m10 3 111.4911
                            2016m11 3 116.66447
                            2016m12 3 148.00323
                            2017m1 3 128.16495
                            2017m2 3 148.71143
                            2017m3 3 149.01871
                            2017m4 3 135.80881
                            2017m5 3 143.77136
                            2017m6 3 140.02286
                            2017m7 3 139.21159
                            2017m8 3 141.24895
                            2017m9 3 139.95776
                            2017m10 3 135.87836
                            2017m11 3 126.39616
                            2017m12 3 135.79721
                            2018m1 3 132.92706
                            2018m2 3 107.04241
                            2018m3 3 96.90815
                            2018m4 3 78.522408
                            2018m5 3 82.812103
                            2018m6 3 92.082253
                            2018m7 3 94.417168
                            2018m8 3 99.399483
                            2018m9 3 105.04055
                            2018m10 3 99.216026
                            2018m11 3 94.808296
                            2018m12 3 104.48966
                            2019m1 3 101.48612
                            2019m2 3 105.99895
                            2019m3 3 107.15462
                            2019m4 3 84.620842
                            2019m5 3 89.71418
                            2019m6 3 90.633171
                            2019m7 3 100.25871
                            2019m8 3 706.08984
                            2019m9 3 702.59308

                            2. Another thing that I have encountered while using one_id runby code is that some of my panels' 2, 4 and others observations are deleted altogether, although they have the data for both Y var as well as X variables in the original dataset. The resultant data in stata with new var _coeff and _se have dropped those panels altogether. please see below my runby one-id output in stata:

                            runby one_id, by(FI_n) status

                            elapsed ----------- by-groups ---------- ------- observations ------ time
                            time count errors no-data processed saved remaining
                            ------------------------------------------------------------------------------------
                            00:00:01 2 1 0 301 153 00:02:07
                            00:00:02 13 5 0 1,900 1,276 00:00:39
                            00:00:03 25 11 0 3,907 2,359 00:00:27
                            00:00:04 41 17 0 6,148 3,793 00:00:21
                            (now reporting every 5 seconds)
                            00:00:09 116 41 0 16,906 12,058 00:00:11
                            00:00:14 191 72 0 26,935 18,930 00:00:06
                            00:00:19 262 93 0 38,101 27,529 00:00:00

                            --------------------------------------
                            Number of by-groups = 262
                            by-groups with errors = 93
                            by-groups with no data = 0
                            Observations processed = 38,101
                            Observations saved = 27,529
                            --------------------------------------

                            3. Lastly, I have to run another regression as:

                            Xit(all panels) = alpha + Xit(each panel one by one) + X2t+X3t+X4t

                            here again can I use runby and one_id commands to regress the entire Xit of all panles as in the data above with Xit(of individual i panels) together with other x variables.If yes, can you please specify the code?

                            Also how would I generate my syntax i the original one_id code to generate the constants(alphas) for each of the regression I ran before in # 9
                            gen coeff_`v' = _b[`v'] gen se_`v' = _se[`v'] Can I use const_'v' _a['v'] (but this doesnot work) Looking forward to you intellectual solutions to the mentioned issues as always.
                            Best Regards
                            Last edited by Aamina Khurraa; 29 Sep 2019, 10:42.

                            Comment


                            • #15
                              1. I'm sorry but I still don't get what you are trying to do. It looks like you want to regress Xi against itself. That makes no sense to me.

                              2. So something is wrong with your data. Re-run the code adding the -verbose- option to the -runby- command and then look for the error messages that come up along the way. They will tell you what the problem is.

                              3. Another one where I don't understand what you are trying to do. What is X2t? What is X3t, X4t? What does (each panel one by one) mean. You are writing equations that I cannot understand. How would you regress Xit from all panels against something from only one panel? I have no idea what you're talking about.

                              Also how would I generate my syntax i the original one_id code to generate the constants(alphas) for each of the regression I ran before in # 9
                              gen coeff_`v' = _b[`v'] gen se_`v' = _se[`v'] Can I use const_'v' _a['v'] (but this doesnot work)
                              It would be -gen constant_term = _b[_cons]- and -gen se_constant = _se[_cons]-.

                              Comment

                              Working...
                              X