Announcement

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

  • Calculating Standard Deviation of the Residuals

    Hi all,
    I ran an ECM and after this, I want to inspect the Standard Deviation of the Residuals plot to see if there is volatile in my model.

    Run model:
    Code:
     regress Dy l(1/7).yi l(1/8).yd l(0/7).x1i l(0/8).x1d l.ei l.ed
    after I get residuals and apply what I read here in #4

    Code:
    predict res, res
    egen daily_sd_res=sd(res), by(date)
    but what I get are just missing values.

    Here a piece of my dataset. Data are
    Code:
    tsset
    time variable:  date, 01jan2015 to 31dec2018
                    delta:  1 day
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(date Dy yi yd x1i x1d ei ed)
    20089             .            0             0            0             0 0   -.08242687
    20090     .02116996    .02116996             0            0             0 0    -.0612569
    20091     .01106596    .01106596             0            0             0 0   -.05019094
    20092    .010417402   .010417402             0            0             0 0   -.03977354
    20093   -.007900596            0   -.007900596            0    -.06892812 0   -.01880446
    20094   -.004676282            0   -.004676282            0    -.01835227 0  -.015794123
    20095   -.002937913            0   -.002937913            0   -.016029835 0   -.01201814
    20096  -.0044448376            0  -.0044448376   .010833502             0 0  -.021000454
    20097    -.01337427            0    -.01337427            0    -.03350556 0   -.02034134
    20098   -.005440772            0   -.005440772            0             0 0   -.02578211
    20099   -.001662135            0   -.001662135            0             0 0  -.027444247
    20100     -.0064767            0     -.0064767            0    -.02196181 0   -.02472252
    20101    .009394586   .009394586             0            0   -.035164475 0 -.0005997333
    20102   -.017572522            0   -.017572522   .019682646             0 0  -.026416086
    20103    -.00355804            0    -.00355804    .03872418             0 0   -.04619326
    20104    -.01020068            0    -.01020068   .006790996             0 0   -.05923827
    20105   -.007450819            0   -.007450819            0             0 0   -.06668909
    20106  -.0016266108            0  -.0016266108            0             0 0    -.0683157
    20107   -.005518496            0   -.005518496   .006149173             0 0    -.0764097
    20108    .000685513   .000685513             0            0    -.02171993 0   -.06662706
    20109    .005839169   .005839169             0  .0046247244             0 0    -.0627249
    20110    .004988313   .004988313             0            0   -.014763355 0   -.05155314
    20111  -.0018172264            0  -.0018172264   .036330104             0 0  -.068586774
    20112  -.0009147525            0  -.0009147525            0             0 0   -.06950153
    20113 -.00013327599            0 -.00013327599            0             0 0    -.0696348
    20114    .002408147   .002408147             0   .006327987             0 0   -.06987706
    20115    .001775384   .001775384             0            0 -.00056409836 0   -.06786541
    20116    .003261387   .003261387             0 .00052559376             0 0   -.06482416
    20117 -.00005555153            0 -.00005555153            0  -.0022336245 0   -.06394418
    20118   .0020005107  .0020005107             0    .01455152             0 0    -.0680384
    20119  .00044727325 .00044727325             0            0             0 0   -.06759112
    20120   .0007092953  .0007092953             0            0             0 0   -.06688183
    20121   .0018749833  .0018749833             0    .08742452             0 0    -.1016235
    20122    .006665409   .006665409             0    .04742861             0 0   -.11482298
    20123    .016419828   .016419828             0  .0019119978             0 0   -.09920397
    20124    .009312987   .009312987             0   .028562784             0 0   -.10185414
    20125    .009942055   .009942055             0            0   -.015233994 0   -.08553152
    20126    .007172227   .007172227             0            0             0 0    -.0783593
    20127  -.0004681349            0  -.0004681349            0             0 0   -.07882743
    20128    .010677457   .010677457             0    .03367603             0 0   -.08225475
    20129     .01244551    .01244551             0            0    -.02256608 0   -.06035772
    20130    .011302948   .011302948             0            0    -.04184544 0  -.031528335
    20131    .005810559   .005810559             0    .05102551             0 0   -.04708917
    20132    .004668951   .004668951             0    .06228065             0 0    -.0685057
    20133   .0046052337  .0046052337             0            0             0 0   -.06390046
    20134   .0020727515  .0020727515             0            0             0 0   -.06182771
    20135    .009067178   .009067178             0    .02068734             0 0   -.06142516
    20136    .003512859   .003512859             0            0   -.007105112 0   -.05493642
    20137   .0021723509  .0021723509             0            0   -.007207036 0   -.04974549
    20138    .002964258   .002964258             0            0    -.03206098 0  -.033352893
    end
    format %td date
    Any suggestions as to why this happens?
    Thanks in advance.

  • #2
    Three points:

    1. regress gives you RMSE which is as good if not better, and fits with standard regression machinery.

    2. With your set-up, residuals are constants for each date: As Stata uses (sample size MINUS 1) not sample size in calculating SD, the result of a division by zero is what you see. There is no point therefore in invoking
    by(date).

    3. Smoothing residuals -- or more precisely some scale like |residual| -- as a function of date seems closer to what you may need.

    Comment

    Working...
    X