Announcement

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

  • rolling dfuller test for panel data - loop

    hi everyone,

    My target is to perform a rolling dfuller test on panel data. Something like asreg or asrol for each panel and date of my data.

    My sample is composed of N stocks and every stock has a specific value (from 1 to N) for "ID" variable and stock returns information "R" in different time/date ranges.

    My sample has missing values and time numerical variable is "obst"

    I am looking for a help about a specific nested loop. I would want to perfom, for every date (obst) and for every stock (ID), a dfuller test on last 250 stock returns (R) observations.
    Then, I want to record some statistics (DFts, CV1,...) of the test stored in r().

    This is my code:

    gen DFts=.
    gen CV1=.
    gen CV5=.
    gen CV10=.
    gen DFpv=.

    gen tmin=.
    gen tmax=.

    qui su ID

    forvalues i = 1/`r(max)' {

    qui su obst if ID == `i'
    replace tmin=`r(min)'+250
    replace tmax=`r(max)'

    forvalues t = tmin/tmax {

    qui dfuller R if ID == `i' in -249/`t'

    replace DFts=r(Zt) if ID==`i' & obst==`t'
    replace CV1=r(cv_1) if ID==`i' & obst==`t'
    replace CV5=r(cv_5) if ID==`i' & obst==`t'
    replace CV10=r(cv_10) if ID==`i' & obst==`t'
    replace DFpv=r(p) if ID==`i' & obst==`t'

    }
    }

    this code yields an error message

    "invalid syntax
    r(198);"



    I hope someone can help me.

    thanks


  • #2
    Repeated significance testing on overlapping chunks of time series?

    That's not what Stata is objecting to. I think Stata needs here something more like

    Code:
    local tmin=`r(min)'+250
    
    forval t = `tmin'/`r(max)' {
    The variables tmin and tmax are not needed at all.

    In short, forval needs to be given scalars, not variables.

    Comment


    • #3
      Nick, thanks for your answer.

      "Repeated significance testing on overlapping chunks of time series?"

      yes, it is exactly in this view.

      With your changes, now it's ok.

      Comment


      • #4
        Glad that the syntax works. Goodness knows what to make of numerous highly dependent significance tests.

        Comment

        Working...
        X