Announcement

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

  • How to calculate the residual variance from a model estimated over one year?

    Dear Stata Users,

    Please, help me to estimate the residual variance from the model estimated over one-year period. The model is "reg ret_rf mktrf" and firm ID is "gvkey", year-month is "fdate". Below I attach a sample of data.



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 gvkey float fdate double mktrf float ret_rf
    "001004" 663                 .0059  -.012540748
    "001004" 664   .013600000000000001   -.02314811
    "001004" 665  -.015300000000000001     .0788761
    "001004" 666                 .0154   -.15202385
    "001004" 667                -.0604    -.0972171
    "001004" 668                -.0308   -.22030418
    "001004" 669                 .0775     .2000528
    "001004" 670   .005600000000000001    .08241511
    "001004" 671                -.0217     .0703398
    "001004" 672  -.057699999999999994   -.19808404
    "001004" 673 -.0007000000000000001    .01312702
    "001004" 674                 .0696    .09280138
    "001004" 675                 .0092   .036212865
    "001004" 676                 .0178    .01529097
    "001004" 677                -.0005   -.04403448
    "001004" 678                 .0395    .03814618
    "001004" 679                  .005    .01842586
    "001004" 680                 .0025    .27245334
    "001004" 681                -.0202   .029333796
    "001004" 682   .048600000000000004    .14662059
    "001004" 683                 .0182   -.10439325
    "001004" 684                 .0194   -.03020331
    "001004" 685   .035699999999999996    .07556119
    "001004" 686  .0017000000000000001   -.02325169
    "001004" 687                 .0109   .071905605
    "001004" 688                 .0106  -.029774856
    "001004" 689  .0078000000000000005  -.005751697
    "001004" 690                 .0187    .07740712
    "001004" 691                 .0016   -.03672888
    "001004" 692   .025099999999999997    .04679821
    "001004" 693                 .0225    .03046582
    "001004" 694   .031200000000000002   .068369515
    "001004" 695                 .0106   -.05597458
    "001004" 696                 .0558   .030841976
    "001004" 697                -.0365     .0510374
    "001004" 698                -.0235    .03473233
    "001004" 699                 .0029   -.01806292
    "001004" 700                 .0265     .0307016
    "001004" 701                 .0048    .03887754
    "001009" 432                 .0226    -.6978484
    "001009" 433   .013300000000000001   -.58284736
    "001013" 432                 .0226    .05391918
    "001013" 433   .013300000000000001   .025226213
    "001013" 434                 .0073   -.13597548
    "001013" 435                 .0206     .2127913
    "001013" 436                 .0236     .0910381
    "001013" 437  -.011399999999999999   -.02573913
    "001013" 438  -.059699999999999996   -.06561111
    "001013" 439                 .0277     .3390953
    "001013" 440                 .0501     .1233533
    "001013" 441                 .0086    .06415938
    "001013" 442                 .0625    .05622907
    "001013" 443                 -.017   -.14597932
    "001013" 444   .049800000000000004    .14811043
    "001013" 445                -.0049   -.25128675
    "001013" 446  -.050199999999999995   -.00892963
    "001013" 447                 .0404  -.032206975
    "001013" 448                 .0674     .3061048
    "001013" 449   .040999999999999995  -.029247444
    "001013" 450                 .0733    .20543782
    "001013" 451                -.0415   -.08459536
    "001013" 452                 .0535   -.12897913
    "001013" 453                 -.038    .01503077
    "001013" 454                 .0298    .11874151
    "001013" 455                 .0132    .11788908
    "001013" 456                 .0015   -.54771316
    "001013" 457                 .0704     .3501984
    "001013" 458   .047599999999999996    .06389661
    "001013" 459                 .0073     .0818678
    "001013" 460  -.030699999999999998   -.06454279
    "001013" 461                 .0318     .2947889
    "001013" 462                -.0246    -.0869769
    "001013" 463   -.16079999999999997    -.3419866
    "001013" 464   .061500000000000006   -.05248732
    "001013" 465                 .0713     .0855574
    "001013" 466                  .061    .29581302
    "001013" 467                 .0616     .1593799
    "001013" 468                  .035    .14218345
    "001013" 469                -.0408   .013768446
    "001013" 470                 .0345    .17316914
    "001013" 471                 .0433 -.0010787679
    "001013" 472                -.0246   .018822223
    "001013" 473    .04769999999999999   -.07177494
    "001013" 474                -.0347  -.027119614
    "001013" 475                -.0138   -.17103484
    "001013" 476                -.0281    .12763457
    "001013" 477                 .0613    .13320878
    "001013" 478                 .0337    .11435544
    "001013" 479    .07719999999999999    .35667855
    "001013" 480  -.047400000000000005    -.0954006
    "001013" 481                 .0245    .35683745
    "001013" 482   .052000000000000005     .1958571
    "001013" 483                 -.064     .1230102
    "001013" 484  -.044199999999999996    .10096707
    "001013" 485                 .0464     .2443721
    "001013" 486  -.025099999999999997       -.0048
    "001013" 487                 .0703   -.02884501
    "001013" 488                -.0545    -.3482298
    "001013" 489                -.0276    -.2107133
    "001013" 490                -.1072   -.06065556
    end
    format %tm fdate
    Last edited by Alberto Alvarez; 24 Jan 2019, 14:09.

  • #2
    After regress issue ereturn list to see what Stata has saved. e(rmse) or e(rss) is probably what you intend. Alternatively, you can use predict to predict residuals and summary to calculate the variance.

    Comment


    • #3
      Alberto:
      Phil's recommendations are clear and fesible.
      However, I would take a step behind:
      - you have a panel dataset: so why asking for one-year residual after -regress- (by the way; if you use pooled OLS in panel data you should -cluster- the standard error on the -panelid-, as your observations are not independent) instead of using -xtreg- (that provides, in turn, different types of residuals: ei, ui, ei+ui)?
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X