universidad nacional autónoma de méxico...* material de apoyo para desarrollar el capítulo 6 de...
TRANSCRIPT
Curso de Econometría de Series de Tiempo
Facultad de Economía
Universidad Nacional Autónoma de México
Profesor: Juan Francisco Islas
Adjunto: Miguel Heras
Ciudad Universitaria, Febrero 2012
Regresión con Series de Tiempo *
http://admin.wadsworth.com/resource_uploads/downloads/0534409776_23696.zip
* Material de apoyo para desarrollar el capítulo 6 de Bowerman, et. al. 4ª. ed. Las bases de datos están en:
Modelo sin tendencia
25
030
035
040
0
Tone
lada
s
0 5 10 15 20 25t
Pesca de bacalao
tty 0
yyF
t 0̂
Intervalo de predicción bajo el modelo sin tendencia
27
530
032
535
037
540
042
5
Tone
lada
s
0 5 10 15 20 25t
Pesca de bacalao
1
11
11 1
2
1
2n
styyn
styP nFnF
95.071.42288.279 yP
use "C:\Bowerman\Chapter 6\Stata\t6-1 cod catch.dta", clear
gen t=_n
gen mes=""
replace mes="Ene" if mod(t,12)==1
replace mes="Feb" if mod(t,12)==2
replace mes="Mar" if mod(t,12)==3
replace mes="Abr" if mod(t,12)==4
replace mes="May" if mod(t,12)==5
replace mes="Jun" if mod(t,12)==6
replace mes="Jul" if mod(t,12)==7
replace mes="Ago" if mod(t,12)==8
replace mes="Sept" if mod(t,12)==9
replace mes="Oct" if mod(t,12)==10
replace mes="Nov" if mod(t,12)==11
replace mes="Dic" if mod(t,12)==0
gen year="Año 1"
replace year="Año 2" in 13/24
tsset t
twoway (scatter y t) (line y t), ylabel(275(25)425) yline(351.2917) title("Pesca de
bacalao") ytitle("Toneladas") legend(off)
regress y
* Intervalo de Predicción para y
display "Cota inferior = ", 351.2917-invttail(_N-1,.025)*33.825*sqrt(1+1/_N)
display "Cota superior = ", 351.2917+invttail(_N-1,.025)*33.825*sqrt(1+1/_N)
twoway (scatter y t) (line y t), ylabel(275(25)425) yline(279.88 351.2917 422.71)
title("Pesca de bacalao") ytitle("Toneladas") legend(off)
Modelo sin tendencia. Código en Stata
Modelo con tendencia lineal
10
015
020
025
030
035
040
045
050
0
Ca
lcula
dora
s
0 2 4 6 8 10 12 14 16 18 20 22 24 26t
Ventas
tt ty 10
tyF
t 10ˆˆ
15
020
025
030
035
040
045
0
Ca
lcula
dora
s
0 2 4 6 8 10 12 14 16 18 20 22 24 26t
y y
Fitted values forecast
forecast
Ventas
Intervalo de predicción bajo el modelo con tendencia lineal
124
11
24
11
24
1
2
2
02
2
24
1
2
2
02
2
t
nF
t
nF
tt
ttstyy
tt
ttstyP
95.0471.2328.6 yP
use "C:\Bowerman\Chapter 6\Stata\t6-2 calculator.dta", clear
gen t=_n
gen mes=""
replace mes="Ene" if mod(t,12)==1
replace mes="Feb" if mod(t,12)==2
replace mes="Mar" if mod(t,12)==3
replace mes="Abr" if mod(t,12)==4
replace mes="May" if mod(t,12)==5
replace mes="Jun" if mod(t,12)==6
replace mes="Jul" if mod(t,12)==7
replace mes="Ago" if mod(t,12)==8
replace mes="Sept" if mod(t,12)==9
replace mes="Oct" if mod(t,12)==10
replace mes="Nov" if mod(t,12)==11
replace mes="Dic" if mod(t,12)==0
gen year="Año 1"
replace year="Año 2" in 13/24
tsset t
twoway (scatter y t) (line y t), ylabel(100(50)500) yline(298.9583) title("Ventas") ytitle("Calculadoras")
legend(off)
regress y t
gen forecast=y in 24
* Pronóstico de y25
set obs 26
for num 25/26:replace t=X in X
replace mes="Ene" in 25
replace mes="Feb" in 26
replace year="Año 3" in 25/26
for num 25/26:replace forecast=_b[_cons]+_b[t]*X in X
* Intervalo de Predicción para el pronóstico de y25
display "Cota inferior = ", forecast[25]-invttail(24-2,.025)*31.671*sqrt(1+1/24+((25-12.5)^2)/(24*47.91666667))
display "Cota superior = ", forecast[25]+invttail(24-2,.025)*31.671*sqrt(1+1/24+((25-12.5)^2)/(24*47.91666667))
* Intervalo de Predicción para el pronóstico de y26
display "Cota inferior = ", forecast[26]-invttail(24-2,.025)*31.671*sqrt(1+1/24+((26-12.5)^2)/(24*47.91666667))
display "Cota superior = ", forecast[26]+invttail(24-2,.025)*31.671*sqrt(1+1/24+((26-12.5)^2)/(24*47.91666667))
twoway (scatter y t) (line y t)(scatter forecast t) (line forecast t), xlabel(0(2)26) ylabel(100(50)500)
yline(298.9583) title("Ventas") ytitle("Calculadoras") legend(off)
predict yhat
twoway (scatter y t) (line y t)(line yhat t) (scatter forecast t) (line forecast t), xlabel(0(2)26)
ylabel(150(50)450) yline(298.9583) title("Ventas") ytitle("Calculadoras")
Modelo con tendencia lineal. Código en Stata
Modelo con tendencia cuadrática 20
040
060
080
010
00
12
00
Mile
s d
e d
óla
res
0 2 4 6 8 10 12 14 16 18 20 22 24 26t
Solicitudes de préstamo
tt tty 2
110
2
110ˆˆˆ ttyF
t 20
040
060
080
010
00
12
00
Mile
s d
e d
óla
res
0 5 10 15 20 25t
y y
Fitted values
Solicitudes de Préstamo
Intervalo de predicción bajo el modelo con tendencia cuadrática
1''1''1 0
1
0
3
2
0
1
0
3
2
xXXxstyyxXXxstyP nFnF
95.0.32196,109.040,1 yP
use "C:\Bowerman\Chapter 6\Stata\t6-3 loans.dta", clear
gen t=_n
gen mes=""
replace mes="Ene" if mod(t,12)==1
replace mes="Feb" if mod(t,12)==2
replace mes="Mar" if mod(t,12)==3
replace mes="Abr" if mod(t,12)==4
replace mes="May" if mod(t,12)==5
replace mes="Jun" if mod(t,12)==6
replace mes="Jul" if mod(t,12)==7
replace mes="Ago" if mod(t,12)==8
replace mes="Sept" if mod(t,12)==9
replace mes="Oct" if mod(t,12)==10
replace mes="Nov" if mod(t,12)==11
replace mes="Dic" if mod(t,12)==0
gen year="Año 1"
replace year="Año 2" in 13/24
tsset t
twoway (scatter y t) (line y t), ylabel(200(200)1200) yline(720.4167) title("Solicitudes de Préstamo")
ytitle("Miles de dólares") legend(off)
gen t2=t*t
regress y t t2
gen i=1
mkmat i t t2,matrix(x)
matrix list x
matrix xt=x'
matrix xtx=x'*x
matrix invxtx=inv(xtx)
matrix list invxtx
gen forecast=y in 24
* Pronósticos de y25 y y26
set obs 26
for num 25/26:replace t=X in X
replace mes="Ene" in 25
replace mes="Feb" in 26
replace year="Año 3" in 25/26
for num 25/26:replace forecast=_b[_cons]+_b[t]*X+_b[t2]*X*X in X
Modelo con tendencia cuadrática. Código en Stata
* Intervalo de Predicción para el pronóstico de y25
matrix x0=J(3,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=25
matrix x0[3,1]=25*25
matrix list x0
matrix s=x0'*invxtx*x0
display "Cota inferior = ", forecast[25]-invttail(24-3,.025)*31.247*sqrt(1+s[1,1])
display "Cota superior = ", forecast[25]+invttail(24-3,.025)*31.247*sqrt(1+s[1,1])
* Intervalo de Predicción para el pronóstico de y26
matrix x0=J(3,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=26
matrix x0[3,1]=26*26
matrix list x0
matrix s=x0'*invxtx*x0
display "Cota inferior = ", forecast[26]-invttail(24-3,.025)*31.247*sqrt(1+s[1,1])
display "Cota superior = ", forecast[26]+invttail(24-3,.025)*31.247*sqrt(1+s[1,1])
twoway (scatter y t) (line y t)(scatter forecast t) (line forecast t), xlabel(0(2)26) ylabel(200(200)1200)
yline(720.4167) title("Solicitudes de préstamo") ytitle("Miles de dólares") legend(off)
predict yhat
twoway (scatter y t) (line y t) (line yhat t), ylabel(200(200)1200) yline(720.4167) title("Solicitudes de
Préstamo") ytitle("Miles de dólares")
Modelo con tendencia cuadrática. Código en Stata
Transformación de series de tiempo con variación estacional 40
060
080
010
00
12
00
y
0 50 100 150 200t
Promedio Mensual
Habitaciones de hotel ocupadas durante 14 años
6.2
6.4
6.6
6.8
7
logh
0 50 100 150 200t
logaritmo
4.5
55.5
6
sqr4
0 50 100 150 200t
raíz cuarta
20
25
30
35
sqr2
0 50 100 150 200t
raíz cuadrada
Modelo con tendencia cuadrática. Código en Stata
use "C:\Bowerman\Chapter 6\Stata\t6-4 hotel.dta", clear
gen t=_n
tsset t
twoway (scatter y t, title("Habitaciones de hotel ocupadas
durante 14 años") subtitle("Promedio Mensual") msize(small))
(line y t), yline(722.2976) legend(off)
saving("C:\Bowerman\Chapter 6\Stata\datos hotel.gph",replace)
gen sqr2=sqrt(y)
twoway (scatter sqr2 t, title("raíz cuadrada") msize(small))
(line sqr2 t), legend(off) yline(26.75034)
saving("C:\Bowerman\Chapter 6\Stata\sqr2 hotel.gph",replace)
gen sqr4=y^(1/4)
twoway (scatter sqr4 t, title("raíz cuarta") msize(small)) (line
sqr4 t), legend(off) yline(5.166101) saving("C:\Bowerman\Chapter
6\Stata\sqr4 hotel.gph",replace)
gen logh=log(y)
twoway (scatter logh t, title("logaritmo") msize(small)) (line
logh t), legend(off) yline(6.563887) saving("C:\Bowerman\Chapter
6\Stata\logh hotel.gph",replace)
Modelo de variación estacional mediante variables dicotómicas
tt MMty 11121210log tttt ISTy datos mensuales
Pronósticos e intervalos de predicción
1''1loglog''1log 0
1
0
13
2
0
1
0
13
2
xXXxstyyxXXxstyP nFnF
95.07503.6log6628.6 yP
10
10
13
2
01
013
2
''1log''1log xXXxstyxXXxsty nFnF
eyeP
95.07503.66628.6 eyeP
95.029.85473.782 yP
Periodo
Predicción Intervalos de Predicción
y* = log(y) y = exp(y*) y* = log(y) y = exp(y*)
Pronóstico puntual Cota
Inferior
Cota
Superior
Cota
Inferior
Cota
Superior
169 6.7065 817.72 6.6628 6.7503 782.72 854.29
170 6.6388 764.16 6.5950 6.6825 731.45 798.33
171 6.6691 787.70 6.6254 6.7129 753.99 822.92
172 6.7961 894.39 6.7524 6.8399 856.11 934.38
173 6.7794 879.56 6.7357 6.8232 841.92 918.89
174 6.9087 1,000.91 6.8649 6.9524 958.07 1,045.66
175 7.0535 1,156.91 7.0098 7.0972 1,107.39 1,208.63
176 7.0784 1,186.07 7.0347 7.1221 1,135.31 1,239.10
177 6.8259 921.42 6.7822 6.8697 881.99 962.62
178 6.8122 908.87 6.7685 6.8559 869.97 949.51
179 6.6632 783.03 6.6194 6.7069 749.51 818.04
180 6.7781 878.40 6.7344 6.8219 840.81 917.68
Pronósticos e intervalos de predicción
Resultados bajo el Modelo de factores estacionales mediante variables dummy
Regresión con variables dicotómicas. Código en Stata
log using "C:\Bowerman\Chapter 6\Stata\Resultados hotel.log", replace
use "C:\Bowerman\Chapter 6\Stata\t6-4 hotel.dta", clear
gen t=_n
gen double logh=log(y)
gen mes=.
replace mes=1 if mod(t,12)==1
replace mes=2 if mod(t,12)==2
replace mes=3 if mod(t,12)==3
replace mes=4 if mod(t,12)==4
replace mes=5 if mod(t,12)==5
replace mes=6 if mod(t,12)==6
replace mes=7 if mod(t,12)==7
replace mes=8 if mod(t,12)==8
replace mes=9 if mod(t,12)==9
replace mes=10 if mod(t,12)==10
replace mes=11 if mod(t,12)==11
replace mes=12 if mod(t,12)==0
sort mes
tabulate mes, gen(mes)
tsset t
regress logh t mes1-mes11
dwstat
gen i=1
mkmat i t mes1-mes11,matrix(x)
matrix list x
matrix xt=x'
matrix xtx=x'*x
matrix invxtx=inv(xtx)
matrix list invxtx
Regresión con variables dicotómicas. Código en Stata
* Pronósticos de y169 a y180
set obs 180
for num 169/180:replace t=X in X
replace logh=_b[_cons]+_b[t]*169+_b[mes1] in 169
replace logh=_b[_cons]+_b[t]*170+_b[mes2] in 170
replace logh=_b[_cons]+_b[t]*171+_b[mes3] in 171
replace logh=_b[_cons]+_b[t]*172+_b[mes4] in 172
replace logh=_b[_cons]+_b[t]*173+_b[mes5] in 173
replace logh=_b[_cons]+_b[t]*174+_b[mes6] in 174
replace logh=_b[_cons]+_b[t]*175+_b[mes7] in 175
replace logh=_b[_cons]+_b[t]*176+_b[mes8] in 176
replace logh=_b[_cons]+_b[t]*177+_b[mes9] in 177
replace logh=_b[_cons]+_b[t]*178+_b[mes10] in 178
replace logh=_b[_cons]+_b[t]*179+_b[mes11] in 179
replace logh=_b[_cons]+_b[t]*180 in 180
replace y=exp(_b[_cons]+_b[t]*169+_b[mes1]) in 169
replace y=exp(_b[_cons]+_b[t]*170+_b[mes2]) in 170
replace y=exp(_b[_cons]+_b[t]*171+_b[mes3]) in 171
replace y=exp(_b[_cons]+_b[t]*172+_b[mes4]) in 172
replace y=exp(_b[_cons]+_b[t]*173+_b[mes5]) in 173
replace y=exp(_b[_cons]+_b[t]*174+_b[mes6]) in 174
replace y=exp(_b[_cons]+_b[t]*175+_b[mes7]) in 175
replace y=exp(_b[_cons]+_b[t]*176+_b[mes8]) in 176
replace y=exp(_b[_cons]+_b[t]*177+_b[mes9]) in 177
replace y=exp(_b[_cons]+_b[t]*178+_b[mes10]) in 178
replace y=exp(_b[_cons]+_b[t]*179+_b[mes11]) in 179
replace y=exp(_b[_cons]+_b[t]*180) in 180
Regresión con variables dicotómicas. Código en Stata
* Intervalos de Predicción para los Pronósticos de y169 a y180
* Pronósticos de y169
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=169
matrix x0[3,1]=1
for num 4/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y169) = P[", logh[169]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y <
", logh[169]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y169 = P[", exp(logh[169]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y <
", exp(logh[169]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
* Pronósticos de y170
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=170
matrix x0[3,1]=0
matrix x0[4,1]=1
for num 5/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y170) = P[", logh[170]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y <
", logh[170]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y170 = P[", exp(logh[170]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y <
", exp(logh[170]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
* Pronósticos de y171
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=171
for num 3/4: matrix x0[X,1]=0
matrix x0[5,1]=1
for num 6/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y171) = P[", logh[171]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y <
", logh[171]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y171 = P[", exp(logh[171]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y <
", exp(logh[171]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
Regresión con variables dicotómicas. Código en Stata
* Pronósticos de y172
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=172
for num 3/5: matrix x0[X,1]=0
matrix x0[6,1]=1
for num 7/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y172) = P[", logh[172]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y < ", logh[172]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y172 = P[", exp(logh[172]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y < ",
exp(logh[172]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
* Pronósticos de y173
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=173
for num 3/6: matrix x0[X,1]=0
matrix x0[7,1]=1
for num 8/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y173) = P[", logh[173]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y < ", logh[173]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y173 = P[", exp(logh[173]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y < ",
exp(logh[173]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
* Pronósticos de y174
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=174
for num 3/7: matrix x0[X,1]=0
matrix x0[8,1]=1
for num 9/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y174) = P[", logh[174]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y < ", logh[174]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y174 = P[", exp(logh[174]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y < ",
exp(logh[174]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
* Pronósticos de y175
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=175
for num 3/8: matrix x0[X,1]=0
matrix x0[9,1]=1
for num 10/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y175) = P[", logh[175]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y < ", logh[175]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y175 = P[", exp(logh[175]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y < ",
exp(logh[175]+invttail(168-13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
Regresión con variables dicotómicas. Código en Stata
* Pronósticos de y176
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=176
for num 3/9: matrix x0[X,1]=0
matrix x0[10,1]=1
for num 11/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y176) = P[", logh[176]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y < ", logh[176]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y176 = P[", exp(logh[176]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y < ", exp(logh[176]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
* Pronósticos de y177
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=177
for num 3/10: matrix x0[X,1]=0
matrix x0[11,1]=1
for num 12/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y177) = P[", logh[177]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y < ", logh[177]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y177 = P[", exp(logh[177]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y < ", exp(logh[177]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
* Pronósticos de y178
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=178
for num 3/11: matrix x0[X,1]=0
matrix x0[12,1]=1
matrix x0[13,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y178) = P[", logh[178]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y < ", logh[178]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y178 = P[", exp(logh[178]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y < ", exp(logh[178]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
* Pronósticos de y179
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=179
for num 3/12: matrix x0[X,1]=0
matrix x0[13,1]=1
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y179) = P[", logh[179]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y < ", logh[179]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y179 = P[", exp(logh[179]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y < ", exp(logh[179]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
* Pronósticos de y180
matrix x0=J(13,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=180
for num 3/13: matrix x0[X,1]=0
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y180) = P[", logh[180]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1])," < y < ", logh[180]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y180 = P[", exp(logh[180]-invttail(168-13,.025)*.02119*sqrt(1+s[1,1]))," < y < ", exp(logh[180]+invttail(168-
13,.025)*.02119*sqrt(1+s[1,1])),"] = 0.95"
log close
Modelo de variación estacional mediante funciones trigonométricas
tt
ttttty
12
4cos
12
4cos
12
2sen
12
2senlog 543210
Pronósticos e intervalos de predicción
Periodo
Predicción Intervalos de Predicción
y* =
log(y)
y =
exp(y*) y* = log(y) y = exp(y*)
Pronóstico puntual Cota
Inferior
Cota
Superior
Cota
Inferior
Cota
Superior
169 6.7018 813.83 6.5885 6.8150 726.66 911.46
170 6.6949 808.30 6.5815 6.8083 721.66 905.34
171 6.6806 796.79 6.5672 6.7940 711.37 892.47
172 6.7123 822.44 6.5989 6.8257 734.29 921.18
173 6.8173 913.51 6.7039 6.9306 815.61 1,023.16
174 6.9543 1,047.68 6.8410 7.0677 935.40 1,173.44
175 7.0385 1,139.63 6.9251 7.1518 1,017.47 1,276.46
176 7.0128 1,110.76 6.8994 7.1262 991.69 1,244.13
177 6.8989 991.14 6.7855 7.0122 884.91 1,110.12
178 6.7768 877.29 6.6635 6.8902 783.29 982.59
179 6.7153 824.90 6.6019 6.8286 736.49 923.92
180 6.7174 826.70 6.6040 6.8309 738.02 926.02
Resultados bajo el Modelo de regresión trigonométrica
Regresión trigonométrica. Código en Stata
program drop _all
log using "C:\Bowerman\Chapter 6\Stata\Resultados hotel.log", replace
use "C:\Bowerman\Chapter 6\Stata\t6-4 hotel.dta", clear
gen t=_n
gen double logh=log(y)
gen mes=.
replace mes=1 if mod(t,12)==1
replace mes=2 if mod(t,12)==2
replace mes=3 if mod(t,12)==3
replace mes=4 if mod(t,12)==4
replace mes=5 if mod(t,12)==5
replace mes=6 if mod(t,12)==6
replace mes=7 if mod(t,12)==7
replace mes=8 if mod(t,12)==8
replace mes=9 if mod(t,12)==9
replace mes=10 if mod(t,12)==10
replace mes=11 if mod(t,12)==11
replace mes=12 if mod(t,12)==0
gen double sen2=sin(2*_pi*t/12)
gen double cos2=cos(2*_pi*t/12)
gen double sen4=sin(4*_pi*t/12)
gen double cos4=cos(4*_pi*t/12)
tsset t
regress logh t sen2 cos2 sen4 cos4
dwstat
gen i=1
mkmat i t sen2 cos2 sen4 cos4, matrix(x)
matrix list x
matrix xt=x'
matrix xtx=x'*x
matrix invxtx=inv(xtx)
matrix list invxtx
40
060
080
010
00
12
00
0 50 100 150 200t
y yhatr
* Pronósticos de y169 a y180
set obs 180
for num 169/180:replace t=X in X
for num 169/180:replace
logh=_b[_cons]+_b[t]*X+_b[sen2]*sin(2*_pi*X/12)+_b[cos2]*cos(2*_pi*X/12)+_b[sen4]*sin(4*_pi*X
/12)+_b[cos4]*cos(4*_pi*X/12) in X
for num 169/180:replace
y=exp(_b[_cons]+_b[t]*X+_b[sen2]*sin(2*_pi*X/12)+_b[cos2]*cos(2*_pi*X/12)+_b[sen4]*sin(4*_pi*
X/12)+_b[cos4]*cos(4*_pi*X/12)) in X
* Intervalos de Predicción para los Pronósticos de y169 a y180
program define loop
matrix x0=J(6,1,0)
matrix x0[1,1]=1
matrix x0[2,1]=`1'
matrix x0[3,1]=sin(2*_pi*`1'/12)
matrix x0[4,1]=cos(2*_pi*`1'/12)
matrix x0[5,1]=sin(4*_pi*`1'/12)
matrix x0[6,1]=cos(4*_pi*`1'/12)
matrix list x0
matrix s=x0'*invxtx*x0
display "Intervalo de Predicción Pronóstico log(y`1') = P[", logh[`1']-invttail(168-
6,.025)*.05602*sqrt(1+s[1,1])," < y < ", logh[`1']+invttail(168-
6,.025)*.05602*sqrt(1+s[1,1]),"] = 0.95"
display "Intervalo de Predicción Pronóstico y`1' = P[", exp(logh[`1']-invttail(168-
6,.025)*.05602*sqrt(1+s[1,1]))," < y < ", exp(logh[`1']+invttail(168-
6,.025)*.05602*sqrt(1+s[1,1])),"] = 0.95"
end
for num 169/180: loop X
predict yhat
gen double yhatr=exp(yhat)
twoway (line y t) (line yhatr t)
log close
Regresión trigonométrica. Código en Stata
0
10
020
030
040
0y
0 5 10 15t
Aperturas de Western Steakhouse
Modelo de crecimiento
t
t
ty 10
23
45
6
ly
0 5 10 15t
log(Aperturas de Western Steakhouse)
tt ty loglogloglog 10
tt uty 10log
Modelo de crecimiento
115
11lnln
15
11ln
15
1
2
2
02
2
15
1
2
2
02
2
t
nF
t
nF
tt
ttstyy
tt
ttstyP
1
15
1
2
202
2
15
1
2
202
215
11ln
15
11ln
t
nF
t
nF
tt
ttsty
tt
ttsty
eyeP
Modelo de crecimiento. Predicción
Modelo de crecimiento. Código en Stata
use "C:\Bowerman\Chapter 6\Stata\t6-5 steakhouse.dta", clear
gen double ly=log(y)
gen t=_n
tsset t
twoway (scatter y t) (line y t), yline(109.3333) legend(off) title("Aperturas de Western
Steakhouse")
twoway (scatter ly t) (line ly t), yline(4.125163) legend(off) title("log(Aperturas de
Western Steakhouse)")
* Estimación MCO
reg ly t
dwstat
display exp(.2568804)
display (exp(.2568804)-1)*100
* Predicción puntual de y16
set obs 16
replace t=16 in 16
replace ly=_b[_cons]+_b[t]*t in 16
display exp(6.1802065)
replace y=exp(6.1802065) in 16
list
* Intervalo de Predicción para log(y16)
display "Cota inferior = ", ly[16]-invttail(15-2,.025)*.07552*sqrt(1+1/15+((16-
8)^2)/(15*18.666667))
display "Cota superior = ", ly[16]+invttail(15-2,.025)*.07552*sqrt(1+1/15+((16-
8)^2)/(15*18.666667))
* Intervalo de Predicción para y16
display "Cota inferior = ", exp(ly[16]-invttail(15-2,.025)*.07552*sqrt(1+1/15+((16-
8)^2)/(15*18.666667)))
display "Cota superior = ", exp(ly[16]+invttail(15-2,.025)*.07552*sqrt(1+1/15+((16-
8)^2)/(15*18.666667)))
Autocorrelación de Primer Orden. Proceso AR(1)
tt MMty 11121210log
ttt a 11con
Autocorrelación de Primer Orden. Proceso AR(1). Código en Stata
use "C:\Bowerman\Chapter 6\Stata\t6-4 hotel.dta", clear
gen t=_n
gen double logh=log(y)
gen mes=.
replace mes=1 if mod(t,12)==1
replace mes=2 if mod(t,12)==2
replace mes=3 if mod(t,12)==3
replace mes=4 if mod(t,12)==4
replace mes=5 if mod(t,12)==5
replace mes=6 if mod(t,12)==6
replace mes=7 if mod(t,12)==7
replace mes=8 if mod(t,12)==8
replace mes=9 if mod(t,12)==9
replace mes=10 if mod(t,12)==10
replace mes=11 if mod(t,12)==11
replace mes=12 if mod(t,12)==0
sort mes
tabulate mes, gen(mes)
tsset t
arima logh t mes1-mes11, ar(1)