Announcement

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

  • Forecasting Code with constrained regression

    Hi folks,
    I am new on the forum and to be honest I am not an expert of Stata either.
    I am performing for my master thesis out of sample forecasts with rolling technique. I got stuck on running the following code which is aimed to include a constrained regression



    constraint define 1 l.PPP_2=0.840896415253715
    program fcst_ppcad, rclass
    syntax [if]

    qui tsset
    local timevar `r(timevar)'
    local first `r(tmin)'

    cnsreg PPP l.PPP_2, constraints(l.PPP_2=0.84089) `if'
    summarize `timevar' if e(sample)

    local last = `r(max)' -`first'+1
    local fcast = _b[_cons] + _b[l.PPP_2]* ///
    PPP_2[`last']

    return scalar fcast= `fcast'
    return scalar actual = PPP[`last'+1]
    return scalar sqerror = (PPP[`last'+1]- ///
    `fcast')^2
    end

    rolling pppcad_sqerr=r(sqerror) pppcad_fcast=r(fcast) actual=r(actual), window(148) saving(pppcad_q7, replace): fcst_ppcad



    The objective would be to have the coefficient in the estimatie equal to 0.840896415253715 and this code doesn't work in the right manner.
    Please, any suggestions is really appreciated.

    Thanks!!!
Working...
X