当使用滞后结果作为回归量时,如何让Stata产生动态预测?

问题描述 投票:1回答:2

我目前正在处理非常小的数据集(20个观察结果,我知道这很糟糕)。但我需要以某种方式预测价值观。当我简单地在因变量上回归时间时,我能够得到预测,但是当我添加滞后或差异变量时,它预测未来一年以上。这是因为观察太少了吗?

这是我的上下文代码。这两行已经对现有数据进行了更好的拟合预测,但只生成了一个未来预测。

use "scrappage.dta", clear

drop if year == 1993

tsappend, add(12)

tsset year, y

reg scrappagerate year

*reg scrappagerate year l.scrappagerate l2.scrappagerate

*reg scrappagerate year d.scrappagerate d2.scrappagerate

predict p

predict yp if year>year(2013)

tsline yp p scrappagerate

很抱歉,如果这是一个愚蠢的问题,这是我第一次使用Stata预测值。

time-series stata forecasting predict
2个回答
0
投票

看看here的解决方案和解释。基本上,您可以使用arima来估计没有AR或MA组件的模型(应该等同于带有reg的OLS)并创建动态/递归预测:

arima y L(1/2).y, hessian
predict y_dynhat, dyn(tm(2011m2)))

只需将2011m2替换为您观察到的实际上个月日期。粗麻布选项将强制标准错误更紧密地匹配OLS。

您可以考虑在the stats site上发布您的数据,看看人们是否有更好的OLS建模建议。


0
投票

Here's your problem:

您只获得一个预测的原因与预测函数无关,而是与数据的性质无关。假设您有N观察结果。在你的情况下,你使用tsappend, add(12),使它有N+12观察。而你的l1.y滞后变量将延续到N+1th行。

Stata的predict函数将预测所有可用预测变量的非缺失数据。因此,由于您的自变量,l1.y填充在N + 1行,Stata将预测该观察。 (同样,predict不会预测第一次观察,因为您的滞后预测器将丢失。)

Here's your solution:

为了在Stata中使用OLS回归进行动态预测,您需要将此N+1th预测提供到X矩阵中,并使用回归系数矩阵来预测N+2观测。然后你迭代。

* Example of how to do dynamic prediction using OLS regression and lagged variables
clear
set obs 12
gen time = _n
gen y = rnormal(100,100)

tsset time
tsappend, add(12)
gen y_lag1 = l1.y

* Establish the regression relationship and save the coefficients
regress y y_lag1
matrix a = r(table)'
matrix beta = a[1..2,1]

* Predict the N+1 value (notice you have y_lag1 in the 13th row)
predict yhat

* Predict the next values
local lag = 1
forval i = 14/24 {
    local last_y = yhat[`i'-`lag']
    matrix xinput = [`last_y',1]
    * Estimate the next sales
    matrix next_y = xinput*beta
    replace yhat = next_y[1,1] in `i'
}

将其与使用ARIMA模型(根据Dimitriy V.Masterov的评论)进行比较,您得到的结果几乎相同。

arima y l1.y
predict yhat_ar, dyn(13)
© www.soinside.com 2019 - 2024. All rights reserved.