Announcement

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

  • out-of-sample regression with regression that adds one additional value in loop

    Hi Forum!



    I a trying to run a regression that adds one additional value over time starting from month 240.
    I want to put this into a loop construction
    example:
    first regression: newey ret1 CSV, lag(1), if dm==240
    second regression: newey ret1 CSV, lag(1), if dm==241
    third regression: newey ret1 CSV, lag(1), if dm==242
    etc...
    Then, I want to predict the out-of-sample return
    Does anyone know how to do this?
    Thank you in advance.

    my data looks like this:

    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(dm ret1 CSV) str6 Date
    -96 -.02585976 . "195201"
    -95 .04540043 . "195202"
    -94 -.04848516 . "195203"
    -93 .032517504 . "195204"
    -92 .0390429 . "195205"
    -91 .009141531 . "195206"
    -90 -.007571193 . "195207"
    -89 -.02009534 . "195208"
    -88 -.006578268 . "195209"
    -87 .06119964 . "195210"
    -86 .02973347 . "195211"
    -85 -.0033942265 .11431616 "195212"
    -84 -.0026963584 .1160078 "195301"
    -83 -.01419824 .10556794 "195302"
    -82 -.027903305 .10272208 "195303"
    -81 .005213543 .11152158 "195304"
    -80 -.018722516 .11169485 "195305"
    -79 .02429032 .10729206 "195306"
    -78 -.0441937 .094188 "195307"
    -77 .0020020013 .08268259 "195308"
    -76 .04707441 .08208 "195309"
    -75 .02870425 .09014045 "195310"
    -74 .000300045 .09276966 "195311"
    -73 .05263864 .1054452 "195312"
    -72 .016840225 .09274592 "195401"
    -71 .037174303 .09118357 "195402"
    -70 .04362476 .11326773 "195403"
    -69 .03138236 .11295878 "195404"
    -68 .01075745 .1146617 "195405"
    -67 .05116598 .13451011 "195406"
    -66 -.023128344 .14632386 "195407"
    -65 .06598579 .15163665 "195408"
    -64 -.016561328 .14701386 "195409"
    -63 .09834006 .14033738 "195410"
    -62 .05632933 .1258591 "195411"
    -61 .006018036 .14047754 "195412"
    -60 .030660646 .1515092 "195501"
    -59 -.0015987207 .14270325 "195502"
    -58 .03158866 .14474168 "195503"
    -57 .00934338 .12223857 "195504"
    -56 .067692734 .11514062 "195505"
    -55 .01918165 .10023466 "195506"
    -54 .0021022065 .10095424 "195507"
    -53 -.003593528 .08941474 "195508"
    -52 -.026444066 .10444304 "195509"
    -51 .072829984 .09997597 "195510"
    -50 .015011558 .09315722 "195511"
    -49 -.029845556 .09048647 "195512"
    -48 .03841966 .09222206 "195601"
    -47 .06865409 .09598375 "195602"
    -46 .0028039236 .10618235 "195603"
    -45 -.05067113 .10467258 "195604"
    -44 .035412606 .09724966 "195605"
    -43 .04959041 .11837994 "195606"
    -42 -.031299695 .11820288 "195607"
    -41 -.05010137 .12448286 "195608"
    -40 .005213543 .11321782 "195609"
    -39 .003606488 .12336638 "195610"
    -38 .03210458 .12589112 "195611"
    -37 -.03516676 .11634982 "195612"
    -36 -.02038927 .11031085 "195701"
    -35 .021528464 .108548 "195702"
    -34 .0435204 .10250375 "195703"
    -33 .03510203 .10545922 "195704"
    -32 -.007372688 .1059801 "195705"
    -31 .006621828 .12032104 "195706"
    -30 -.04981635 .12308076 "195707"
    -29 -.05804709 .11352706 "195708"
    -28 -.04228017 .1189667 "195709"
    -27 .02326654 .12696272 "195710"
    -26 -.03834546 .14193478 "195711"
    -25 .04770285 .16070096 "195712"
    -24 -.015085063 .13627808 "195801"
    -23 .03324052 .13581073 "195802"
    -22 .03138236 .13421364 "195803"
    -21 .02336887 .13257481 "195804"
    -20 .02973347 .12150589 "195805"
    -19 .04487786 .12550123 "195806"
    -18 .01928357 .10454264 "195807"
    -17 .04770285 .099738 "195808"
    -16 .02562276 .1159516 "195809"
    -15 .030557584 .13760905 "195810"
    -14 .05284918 .15221724 "195811"
    -13 .007125265 .11890766 "195812"
    -12 .009545268 .12738687 "195901"
    -11 .0028039236 .12621173 "195902"
    -10 .03727803 .1618194 "195903"
    -9 .017450511 .2108589 "195904"
    -8 -.002496878 .18487665 "195905"
    -7 .0322078 .211912 "195906"
    -6 -.01380384 .1866824 "195907"
    -5 -.04686621 .1552222 "195908"
    -4 .01288227 .13904184 "195909"
    -3 .016128685 .1554542 "195910"
    -2 .02480259 .1745053 "195911"
    -1 -.067419685 .1540375 "195912"
    0 .011768713 .1541551 "196001"
    1 -.016167874 .1549197 "196002"
    2 -.016954625 .1219312 "196003"
    3 .031691823 .17893103 "196004"
    end


  • #2
    Something like:
    forvalues dmmacro=240/300 {
    newey ret1 CSV if dm<`dmmacro', lag(1),
    }

    You need to read the documentation. That would have shown you where to put the if statement. This code will run the estimates. Note your == instead of < would only give you one observation in most cases.
    In a line before } you need to do your prediction. This is documented in newey postestimation. As with other procedures, you can determine the observations to be predicted with an if statement (before the comma).

    Comment


    • #3
      Thank you Phil for your reply!
      I ran your code and it works.
      Now, I need to predict the r_hat, which is the predicted value of ret1. So basically, after using data on the first 240 observations I predict a r_241hat. so r-hat predicts the return one period ahead. I added the following code, but then I get 540 different columns, how can I get all the variable for one period ahead in one column?

      forvalues dmmacro=240/780 {
      newey ret1 CSV if dm<`dmmacro', lag(1),
      predict ret_hat`dmmacro'
      }

      what wrong in the predict part is that I calculate the predicted r_for all the periods ahead for each regression.

      How can I do this for just one period ahead?

      Thanks in advance!

      Comment

      Working...
      X