差异时间序列模型

时间:2019-12-20 02:48:16

标签: r ecm

我想为一个时间序列运行这种类型的纠错模型:

∆(ln⁡(Y_t ) )= ∝ + γ_1 ∆(ln⁡(〖PIB〗_t ) )+∅_1 ε_(t-1)+μ_1

目标是获得具有不同变量的回归,并将误差项也包含在变量中。

我正在艰难地做到这一点,但我希望有人可以通过其他方式轻松做到这一点:

serie_unica <- unique(boyanza$Sector)


#Estimacion de la boyanza de corto plazo por sector
Boyanza_Corto_Plazo <- function(i) {

  Sector_elegido <- boyanza %>% 
    filter(Sector == serie_unica[i]) #Estimar cada serie por separado

mco_recaudacion <- dynlm(L(Sector_elegido$lrecaudacion)~L(Sector_elegido$lpib))
recaudacion1ini <- coef(mco_recaudacion)[[1]]
recaudacion2ini <- coef(mco_recaudacion)[[2]]
d_mco <- dynlm(Sector_elegido$lrecaudacion~L(Sector_elegido$lrecaudacion)+Sector_elegido$lpib+L(Sector_elegido$lpib))
aini <- 1-coef(d_mco)[[2]]
d0ini <- coef(d_mco)[[3]]
d1ini <- coef(d_mco)[[4]]
D_lrecaudacion <- diff(Sector_elegido$lrecaudacion)
D_lpib <- diff(Sector_elegido$lpib)
L_lrecaudacion <- lag(Sector_elegido$lrecaudacion,1)
L_lpib <- lag(Sector_elegido$lpib,1)
LD_lpib <- lag(diff(Sector_elegido$lpib),1)
bfset <- data.frame(ts.union(cbind(Sector_elegido$lrecaudacion,Sector_elegido$lpib,L_lrecaudacion,L_lpib,D_lrecaudacion,D_lpib,LD_lpib)))
formula <- D_lrecaudacion ~ -a*(L_lrecaudacion-b1-b2*L_lpib)+d0*D_lpib+d1*LD_lpib
lpib_lrecaudacion_nls <- nls(formula, na.action=na.omit, data=bfset,
              start=list(a=aini, b1=recaudacion1ini, b2=recaudacion2ini, 
                         d0=d0ini, d1=d1ini))
kable(tidy_names(lpib_lrecaudacion_nls), 
      caption="Estimacion de parametros para el modelo de correcion de errores")
}

Resultados_Boyanza_CortoPlazo <- lapply(1:length(serie_unica), Boyanza_Corto_Plazo) %>%
  setNames(serie_unica)

这是我的数据

boyanza <- structure(list(Sector = c("Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura", "Agropecuaria", "Manufactura", "Agropecuaria", 
"Manufactura"), Fecha = structure(c(13514, 13514, 13604, 13604, 
13695, 13695, 13787, 13787, 13879, 13879, 13970, 13970, 14061, 
14061, 14153, 14153, 14245, 14245, 14335, 14335, 14426, 14426, 
14518, 14518, 14610, 14610, 14700, 14700, 14791, 14791, 14883, 
14883, 14975, 14975, 15065, 15065, 15156, 15156, 15248, 15248, 
15340, 15340, 15431, 15431, 15522, 15522, 15614, 15614, 15706, 
15706, 15796, 15796, 15887, 15887, 15979, 15979, 16071, 16071, 
16161, 16161, 16252, 16252, 16344, 16344, 16436, 16436, 16526, 
16526, 16617, 16617, 16709, 16709, 16801, 16801, 16892, 16892, 
16983, 16983, 17075, 17075, 17167, 17167, 17257, 17257, 17348, 
17348, 17440, 17440, 17532, 17532, 17622, 17622, 17713, 17713, 
17805, 17805), class = "Date"), lpib = c(23.9208192513736, 24.7319647582932, 
23.9547793577876, 24.7798391526453, 23.7113615363005, 24.8149774885031, 
23.9551561816675, 24.8821010050744, 23.9791871131267, 24.8558392232244, 
24.0609327260839, 24.9701910228009, 23.8522054499151, 24.9503173375001, 
24.0672619240971, 24.9501614508357, 24.0439628065799, 24.8522534989671, 
24.08862751044, 24.9379219931171, 23.8191462398426, 24.9201527857609, 
24.0489012378328, 24.9805072834487, 24.1342125700793, 24.9724691695314, 
24.2363749536441, 25.0618973035633, 23.9301951603667, 25.0438813138428, 
24.1758581146702, 25.116853540493, 24.1553163277134, 25.0816465995181, 
24.269228441101, 25.1474051066843, 24.0423988905311, 25.1485676841393, 
24.1680724981159, 25.2008558670854, 24.2146417516396, 25.1590422450739, 
24.3370349486954, 25.2244062436121, 23.9721365153744, 25.2046104101159, 
24.2250024811208, 25.2755162410203, 24.2581482159441, 25.1888680726842, 
24.4043429274765, 25.2901601006579, 24.0991585782936, 25.2897662868454, 
24.299670204971, 25.3564698732644, 24.3285037210178, 25.2862362685789, 
24.4382015210812, 25.38353198895, 24.1932843840038, 25.400731741936, 
24.4599687669099, 25.4816147161362, 24.4790995700253, 25.4105749125337, 
24.5509178674757, 25.4835592423713, 24.338977945028, 25.5034625326161, 
24.6336525132489, 25.5662013831766, 24.5911964739263, 25.4657880856982, 
24.695033731291, 25.5766373773005, 24.4769376944737, 25.5478739074007, 
24.6039150575164, 25.6314476014617, 24.5981318722398, 25.5560004217414, 
24.755039330747, 25.6215416376154, 24.5199473144748, 25.6054785357995, 
24.7136028738888, 25.6964258190478, 24.6989671055154, 25.6534089669307, 
24.831274745995, 25.756389929803, 24.6085743595799, 25.7214097882784, 
24.7352657879472, 25.7909791673757), lrecaudacion = c(17.3165532745961, 
21.5540727517896, 17.5254173792703, 21.670861418649, 17.7467477823162, 
21.6841512776958, 17.5808879830509, 21.7581534954001, 17.6415398502254, 
21.7331525529579, 17.6764507731631, 21.9123919728989, 17.6380463968909, 
21.9097913180685, 17.4512529136651, 21.8399537723418, 17.406225763291, 
21.9227967908448, 17.6530255112174, 21.9822891684126, 17.6553928856147, 
22.0428459784791, 17.448877302148, 22.060711282171, 17.5206625731235, 
22.0879051223452, 17.6725343233053, 22.1220660921817, 17.766425875705, 
22.0833817549598, 18.1696094586812, 21.9323510784567, 17.777201932113, 
21.8631500561848, 17.5443784626572, 21.8018369475668, 17.5096720403233, 
21.7593763504405, 17.6231117987477, 21.8867036097524, 17.5944826852452, 
22.014404323807, 17.8676508866123, 22.0265238580423, 17.7121597816971, 
22.1921771821384, 17.6023653836924, 22.2188301834985, 17.5991975078308, 
22.3233094942489, 17.694213627511, 22.3608952722807, 17.8822726638377, 
22.4276299180547, 17.9555449536108, 22.5011424750138, 17.8783488578582, 
22.5621408760058, 18.2514969193021, 22.4944203390804, 18.2820155091685, 
22.5229715486123, 18.5125024965362, 22.622312019965, 18.2700852192986, 
22.6507157318225, 18.1048409050765, 22.6106757254605, 18.1106238822944, 
22.6181855728448, 18.1115957383498, 22.6297467977415, 18.1996426513536, 
22.6458690108391, 18.1442227936413, 22.7187545265385, 18.1443607802437, 
22.6957095238767, 18.3144370714263, 22.706132832817, 18.2171204831367, 
22.6551536149017, 18.2790874105239, 22.5499230156297, 18.1391719826773, 
22.6232920327693, 18.1861918357785, 22.5587827151805, 18.6487752293812, 
22.6575653854989, 18.7988843607231, 22.618727517277, 18.672835240355, 
22.6249872062644, 18.938792447297, 22.6243261773279)), row.names = c(NA, 
-96L), class = c("tbl_df", "tbl", "data.frame"))

0 个答案:

没有答案