Announcement

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

  • Estimating a Rolling Probit model ?

    Hi all,
    I want to run a rolling regression using a probit model for a fixed window of 20 quarters, and then estimate the fitted and residual values for the last observation in the window. I have a time series (not panel data).

    A similar code has been developed by Robert Picard in post #18 of this link http://www.statalist.org/forums/foru...l-values/page2

    His code applies an OLS regression rather than a probit. I adjust the model by dropping "by (company)" as I do not have panel data and my new dataset here is time series, and I also change the 5 year window to 20 (quarterly periods).

    My question is now:
    How can I amend the model below in order to apply it for:
    1- A probit model rather than an OLS regression
    2- And then calculate out-of-sample predicted probabilities...I think this might be straight forward if the probit model is estimated and would be the same as fitted below.


    Code:
    * define a linear regression in Mata using quadcross() - help mata cross(), example 2
    mata:
    mata clear
    mata set matastrict on
    real rowvector myreg(real matrix Xall)
    {
        real colvector y, b, Xy
        real matrix X, XX
    
        y    = Xall[.,1]
        X     = Xall[.,2::cols(Xall)]
        
        XX = quadcross(X, X)
        Xy = quadcross(X, y)
        b  = invsym(XX) * Xy
    
        return(rows(X), b')
    }
    end
    
    * regressions over a rolling window of 20 quarters
    gen double constant = 1
    rangestat (myreg) recession lDRGDP3 lshock  constant,  interval(fqdate -20 0) casewise
    rename myreg1 nobs
    rename myreg2 b_lDRGDP3
    rename myreg3 b_lshock
    rename myreg4 b_constant
    
    * calculate fitted value and residual for each observation
    gen double fitted2= b_constant +b_lDRGDP3*DRGDP3+b_lshock*shock
    gen double residual2 =  recession- fitted
    
    replace fitted2=. if nobs<21
    replace residual2=. if nobs<21
    Thank you

  • #2
    Dear all
    If someone can suggest another coding rather than editing the current code, that would also be very helpful.

    Thanks

    Comment


    • #3
      To do this with rangestat (SSC, as you are asked to explain), you need to write your own Mata routine to do probit.

      I don't see why you aren't investigating rolling here.

      Last edited by Nick Cox; 14 Sep 2016, 12:18.

      Comment


      • #4
        I tried to use rolling as following:


        Code:
        rolling _b , window(20) saving(betas, replace): probit US_recession shock
        preserve
        use betas.dta,clear
        rename end fqdate
        save betas.dta,replace
        restore
        drop _merge
        merge 1:1 fqdate using betas.dta
        tsset fqdate
        
        gen fitprob= _b_cons +_b_shock*f.shock
        However, I have found that the coefficients in the betas.dta file have missing values for some quarters.
        When I use
        Code:
        reg
        instead of
        Code:
        probit
        , all my coefficients are not missing.

        Is there anything wrong with using
        Code:
        _b
        in the code that might have results into this?

        This is also part of some red x that I get when I use probit only:
        Code:
        Rolling replications (159)
        ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
        .............................................xxxxx    50
        xxxxxx......................xxxxxxxxxxxxxxxxxxxx..   100
        .....................xxxx..xxxxxxxxx..............   150
        Any advice on how to solve these issues?

        Comment


        • #5
          However, I have found that the coefficients in the betas.dta file have missing values for some quarters.
          And what happens when you run rolling with the noisily option? What do the probit results for the affected quarters tell you?

          Comment


          • #6
            Thanks William
            Well, I have tried the noisily option but it did not alter the results. However it showed exactly where the error was coming from. Given that US_recession is a binary variable, it turns out that in some of the 20 periods windows there might be 0 values for all values of the dependent variable and so the dependent variable does not change. That is probably why the probit did not report results in that case.

            Alternatively, I added
            Code:
            recursive
            to avoid this problem and estimated the probit with an increasing window. It reported coefficients with no missing values. I write my code below.

            However, one issue is still puzzling me: when I calculated the predicted probabilities (out of sample, i.e. using estimated coefficients for the window and multiplying by the next quarter's values of the variable ) I find that most of these probabilities are negative!!!

            In order to check why these probabilities are negative, while they should not be, I tried to multiply the estimated coefficients by the actual variable's value at the end of the window(i.e in sample estimation), but the fitted probabilities are still negative on average!!

            However when I estimate the same probit model for the entire sample and simply use the command
            Code:
            predict
            to get my predicted probabilities (in sample), they are never negative as supposed to be!!

            Can anyone give a hint on what is going on and how to fix it?



            Comment


            • #7
              your'e not calculating the predicted probability correctly. it's not just the product of the coefficients and the variable values. you need to to put it inside a cumulative normal distribution.
              see here: http://www.stata.com/support/faqs/st...-after-probit/

              Comment


              • #8
                But when I run the rolling regression I get :
                US_recession_b_lshock
                US_recession_b_cons

                how can I deal with these in the way you advise?

                Here is my code:
                Code:
                rolling _b , window(20)recursive saving(betas, replace): probit US_recession lshock
                preserve
                use betas.dta,clear
                rename end fqdate
                save betas.dta,replace
                restore
                drop _merge
                merge 1:1 fqdate using betas.dta
                tsset fqdate
                
                gen fitprob= US_recession_b_cons + US_recession_b_lshock*shock
                I upload my data so you can see what I get
                Attached Files

                Comment


                • #9
                  From Ariel's post:

                  it's not just the product of the coefficients and the variable values. you need to to put it inside a cumulative normal distribution.
                  From the output of search cumulative normal distribution, the first entry returned:
                  Code:
                  [FN]    Stat functions  .  normal() cum. standard normal distribution function
                          (help normal())
                  From the document Ariel cited:

                  The predicted probabilities can be computed by
                  . gen phat1 = normprob(_b[gender]*gender + _b[age]*age
                  > + _b[value]*value + _b[_cons])
                  From help normprob():
                  Code:
                      These functions are out-of-date as of Stata 7.  Their replacements are
                  
                          Old function    Equal to new function
                          -------------------------------------
                          ...
                          normprob()      normal()
                          ...
                  That suggests:
                  Code:
                  gen fitprob= normal( US_recession_b_cons + US_recession_b_lshock*shock )
                  In general, the Statalist FAQ recommends you avail yourself of the information at your disposal from the Stata help and search commands.
                  Last edited by William Lisowski; 14 Sep 2016, 17:55.

                  Comment


                  • #10
                    Thanks William and Ariel, that seems to be working fine. I give you both a "like".
                    Thanks a lot

                    Comment

                    Working...
                    X