Announcement

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

  • One step ahead forecasting with a logistic regression

    Hello all,

    Currently I am writing my master thesis and researching the predictive power of volatility, high and low volatility and leverage on the probability of a market crash in the S&P 500 index.

    I have performed my normal lagged logistic regressions (with the optimal amount of lags suggested by the varsoc command), and want to perform an out-of-sample analysis. My data ranges from 1969M1 to 2018M4. From 1982M1 up until 2018M4, I want to obtain a forecast each month based on the data available in the previous months (one-step ahead forecast if I am correct). I have read several forum posts and searched on the internet for quite some time now, and just cannot figure it out on my own.

    An example:
    My dependent variable is CrashMonth which takes on a value of 1 if the return is below a certain benchmark and 0 otherwise.
    My independent variables are lag1Vol, lag2Vol, lag3Vol, lag4Vol, lag5Vol and lag6Vol as suggested by the varsoc command, which are monthly lags of the volatility.

    I am able to use the predict function to for example predict the probability on a market crash in 1982M2 with predict y if DateM<=tm(1982/2).
    This however just gives me a value of 0.0701, which I interpret as the chance of a probability of a market crash in that particular month is 7.01%.
    This however does not provide me with useful information on for example the mean marginal effects of the lagged volatility variables.

    Is there a way to perform a rolling forecast for each month after 1982M2 while using the data of the selected variables in the previous months?
    Is there a way to report the results from such rolling forecast in a clarifying table? Since performing the predict option gives me over 300 data points and will be hard to interpret by any reader.

    I am looking forward to your responses. If you have any questions please feel free ask.

    Max Thorsen







  • #2
    I think I have found something, except I get the message invalid syntax.

    I have created the variable p_outsample = .
    Next to this I also generated a new variable called DateMM which counts from 1 to 592 (the amount of months I have in my dataset).
    I subsequently tried to run this loop:

    forval i=7/592 {
    logit CrashMonth lag1Vol lag2Vol lag3Vol lag4Vol lag5Vol lag6Vol if DateMM=`i'
    predict temp
    replace p_outsample =temp if DateMM==`i'
    drop temp
    }

    I do however get the invalid syntax error. I have a feeling that I am close, but maybe this could help in providing me with an answer.

    Thanks in advance.

    Comment


    • #3
      You'll increase your chances of a useful answer by following the FAQ on asking questions – provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

      I can't debug your code without the stuff, but right off I see if DateMM=`i' which must be if DateMM==`i'
      The rest looks OK to me (not guaranteeing it does what you want!).

      Comment


      • #4
        My excuses. Sorry for any inconvenience caused. Below I have attached my data with the dataex command:

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input double Return byte CrashMonth double(CredittoIPI HighVolDummy LowVolDummy) float(DateM Vol lag1Vol lag2Vol lag3Vol lag4Vol lag5Vol lag6Vol p_outsample DateMM)
        -.008217767520570764 0 2.4694358442509188 .059315766379082216                   0 108  .5257745         .         .         .         .         .         . .  1
         -.04853294067719985 0  2.482737630676982  .03346163525987673                   0 109 .50429845  .5257745         .         .         .         .         . .  2
          .03386418557793749 0 2.4870258430570593 .016811532267262466                   0 110  .4929289 .50429845  .5257745         .         .         .         . .  3
          .02124836277384691 0  2.534781351008037  .01710501118713237                   0 111  .4977238  .4929289 .50429845  .5257745         .         .         . .  4
        -.002220613994817656 0 2.5740342832903678                   0  .03182696245098565 112 .45130125  .4977238  .4929289 .50429845  .5257745         .         . .  5
         -.05718115661911717 0   2.56400998194648  .06263596586015066                   0 113 .54759294 .45130125  .4977238  .4929289 .50429845  .5257745         . .  6
         -.06206486633082113 0   2.56336420144615   .5012640128383877                   0 114  .9881991 .54759294 .45130125  .4977238  .4929289 .50429845  .5257745 .  7
          .03929191242121548 0 2.5637152351243437  .14928710804102416                   0 115  .6478698  .9881991 .54759294 .45130125  .4977238  .4929289 .50429845 .  8
        -.025341970063518512 0 2.5769695706027047  .17548150893186634                   0 116  .6772636  .6478698  .9881991 .54759294 .45130125  .4977238  .4929289 .  9
          .04329316546479498 0 2.5891087757608844  .05175266490967155                   0 117    .56062  .6772636  .6478698  .9881991 .54759294 .45130125  .4977238 . 10
         -.03591068931006312 0   2.63499721934136                   0 .027887613713147973 118  .4853908    .56062  .6772636  .6478698  .9881991 .54759294 .45130125 . 11
        -.018830921748764207 0 2.6775655275485724  .20379395106369397                   0 119  .7197343  .4853908    .56062  .6772636  .6478698  .9881991 .54759294 . 12
         -.07955401545845142 1 2.7204044602206565  .09129215600646984                   0 120  .6125677  .7197343  .4853908    .56062  .6772636  .6478698  .9881991 . 13
          .05135210235016576 0  2.706769786291407   .1678833302457313                   0 121  .6953731  .6125677  .7197343  .4853908    .56062  .6772636  .6478698 . 14
         .001451460088460683 0  2.703044787141839  .15924693569352072                   0 122  .6907331  .6953731  .6125677  .7197343  .4853908    .56062  .6772636 . 15
         -.09484169645480098 1 2.7167967093000835  .23207890749789034                   0 123  .7709381  .6907331  .6953731  .6125677  .7197343  .4853908    .56062 . 16
          -.0629042668107766 0 2.7285919458872336  1.4376025077431611                   0 124 1.9854875  .7709381  .6907331  .6953731  .6125677  .7197343  .4853908 . 17
        -.051327672234469345 0 2.7587259370198702   .5257879149447171                   0 125 1.0999806 1.9854875  .7709381  .6907331  .6953731  .6125677  .7197343 . 18
          .07073319709221768 0 2.7736363261689374  .34839280619669516                   0 126  .9258369 1.0999806 1.9854875  .7709381  .6907331  .6953731  .6125677 . 19
          .04349874195302824 0 2.8008768489177442  .35868410562551006                   0 127  .9433132  .9258369 1.0999806 1.9854875  .7709381  .6907331  .6953731 . 20
          .03246529012743166 0  2.846000540467504  .09409639021269647                   0 128  .6911001  .9433132  .9258369 1.0999806 1.9854875  .7709381  .6907331 . 21
         -.01146555018134769 0  2.910588247771467  .10050348265905601                   0 129  .7032399  .6911001  .9433132  .9258369 1.0999806 1.9854875  .7709381 . 22
          .04635620205438084 0  2.939002854322832 .014226611667950573                   0 130  .6240738  .7032399  .6911001  .9433132  .9258369 1.0999806 1.9854875 . 23
           .0552133532008983 0  2.903882611564127                   0  .19004517962295328 131 .42592815  .6240738  .7032399  .6911001  .9433132  .9258369 1.0999806 . 24
          .03967972545035116 0 2.8866337671344544                   0  .10250223014272682 132  .5144113 .42592815  .6240738  .7032399  .6911001  .9433132  .9258369 . 25
         .009032922343707645 0  2.901151696172075                   0  .11765994262159067 133  .5032537  .5144113 .42592815  .6240738  .7032399  .6911001  .9433132 . 26
          .03613505898550257 0  2.906702762190026                   0   .1791088490142507 134  .4433357  .5032537  .5144113 .42592815  .6240738  .7032399  .6911001 . 27
         .035644623408628145 0 2.8946463692255278                   0  .27487345307950234 135  .3442074  .4433357  .5032537  .5144113 .42592815  .6240738  .7032399 . 28
         -.04244669024725717 0  2.903449887520416                   0  .13937212658450557 136  .4786718  .3442074  .4433357  .5032537  .5144113 .42592815  .6240738 . 29
        .0007023529110277367 0  2.918560136253091   .0517858245184433                   0 137  .6623509  .4786718  .3442074  .4433357  .5032537  .5144113 .42592815 . 30
        end
        format %tmCCyy/nn DateM
        Further, after adjusting my code to:

        Code:
        forval i=7/592 {
        logit CrashMonth lag1Vol lag2Vol lag3Vol lag4Vol lag5Vol lag6Vol if DateMM==`i'
        predict temp
        replace p_outsample =temp if DateMM==`i'
        drop temp
        }
        I get the following message: insufficient observations.

        Anyone knows what I am doing wrong?

        Thanks in advance!

        Comment

        Working...
        X