subroutine  oos_forec_ex

matrix(99,4) coefs
smpl 1985q1  2012q4
for !tau = 1 to 99
  equation eq1.qreg(quant=!tau/100  ,  cov=sandwich)     cpi12m      c   cpi12m(-1)   cpi12m(-2)    cpi12m(-3)
  coefs(!tau,1) =  eq1.@coefs(1) 
  coefs(!tau,2) =  eq1.@coefs(2) 
  coefs(!tau,3) =  eq1.@coefs(3) 
  coefs(!tau,4) =  eq1.@coefs(4) 
next

scalar t_max = 48   ' number of oos periods for a given path
scalar k_max = 250   ' out-of-sample trajectories
matrix(1,1) aux_tau
matrix(3,1) aux_last3
matrix(1,1) oos

for !k = 1 to k_max  

smpl @all
series  cpi_path = cpi12m
series index!k
rndint(index!k,100) 

for !t = 1 to t_max    
  smpl   2011m6+!t   2011m6+!t
' one draw from uniform [0;1] , multiplies it by 100 and round it to an integer between 1 and 99
  stom(index!k,aux_tau)
  scalar tau = aux_tau(1,1)
  if tau = 0 then
       tau = 1
  endif
  if tau = 100 then
       tau = 99
  endif
  smpl   2011m6+!t-3   2011m6+!t-1  
  stom(cpi_path,aux_last3)

' oos 
  smpl   2011m6+!t   2011m6+!t
  oos(1,1) = coefs(tau,1) + coefs(tau,2)*aux_last3(3,1)  + coefs(tau,3)*aux_last3(2,1)  + coefs(tau,4)*aux_last3(1,1)
  mtos(oos,cpi_path)
next

smpl @all
series path!k = cpi_path

next

' compute empirical quantiles q50, 25 and 75 of the out-of-sample trajectories
series q25 = cpi12m
series q50 = cpi12m
series q75 = cpi12m

matrix(k_max,1) paths
matrix(1,1) aux_q1
matrix(1,1) aux_q2
matrix(1,1) aux_q3

for !t = 1 to t_max    
    smpl   2011m6+!t   2011m6+!t
    for !k = 1 to k_max
         stom(path!k,oos)
         paths(!k,1) = oos(1,1) 
    next
    aux_q1(1,1) = @quantile(paths,0.25)    
    aux_q2(1,1) = @quantile(paths,0.50)    
    aux_q3(1,1) = @quantile(paths,0.75)    

    mtos(aux_q1,q25)
    mtos(aux_q2,q50)
    mtos(aux_q3,q75)

next

smpl 1990m1 2015m6

group group02  PATH1 PATH10 PATH100 PATH101 PATH102 PATH103 PATH104 PATH105 PATH106 PATH107 PATH108 PATH109 PATH11 PATH110 PATH111 PATH112 PATH113 PATH114 PATH115 PATH116 PATH117 PATH118 PATH119 PATH12 PATH120 PATH121 PATH122 PATH123 PATH124 PATH125 PATH126 PATH127 PATH128 PATH129 PATH13 PATH130 PATH131 PATH132 PATH133 PATH134 PATH135 PATH136 PATH137 PATH138 PATH139 PATH14 PATH140 PATH141 PATH142 PATH143 PATH144 PATH145 PATH146 PATH147 PATH148 PATH149 PATH15 PATH150 PATH151 PATH152 PATH153 PATH154 PATH155 PATH156 PATH157 PATH158 PATH159 PATH16 PATH160 PATH161 PATH162 PATH163 PATH164 PATH165 PATH166 PATH167 PATH168 PATH169 PATH17 PATH170 PATH171 PATH172 PATH173 PATH174 PATH175 PATH176 PATH177 PATH178 PATH179 PATH18 PATH180 PATH181 PATH182 PATH183 PATH184 PATH185 PATH186 PATH187 PATH188 PATH189 PATH19 PATH190 PATH191 PATH192 PATH193 PATH194 PATH195 PATH196 PATH197 PATH198 PATH199 PATH2 PATH20 PATH200 PATH201 PATH202 PATH203 PATH204 PATH205 PATH206 PATH207 PATH208 PATH209 PATH21 PATH210 PATH211 PATH212 PATH213 PATH214 PATH215 PATH216 PATH217 PATH218 PATH219 PATH22 PATH220 PATH221 PATH222 PATH223 PATH224 PATH225 PATH226 PATH227 PATH228 PATH229 PATH23 PATH230 PATH231 PATH232 PATH233 PATH234 PATH235 PATH236 PATH237 PATH238 PATH239 PATH24 PATH240 PATH241 PATH242 PATH243 PATH244 PATH245 PATH246 PATH247 PATH248 PATH249 PATH25 PATH250 PATH26 PATH27 PATH28 PATH29 PATH3 PATH30 PATH31 PATH32 PATH33 PATH34 PATH35 PATH36 PATH37 PATH38 PATH39 PATH4 PATH40 PATH41 PATH42 PATH43 PATH44 PATH45 PATH46 PATH47 PATH48 PATH49 PATH5 PATH50 PATH51 PATH52 PATH53 PATH54 PATH55 PATH56 PATH57 PATH58 PATH59 PATH6 PATH60 PATH61 PATH62 PATH63 PATH64 PATH65 PATH66 PATH67 PATH68 PATH69 PATH7 PATH70 PATH71 PATH72 PATH73 PATH74 PATH75 PATH76 PATH77 PATH78 PATH79 PATH8 PATH80 PATH81 PATH82 PATH83 PATH84 PATH85 PATH86 PATH87 PATH88 PATH89 PATH9 PATH90 PATH91 PATH92 PATH93 PATH94 PATH95 PATH96 PATH97 PATH98 PATH99 Q25 Q50 Q75 CPI12M  

' plots the graph  
'delete graph2
graph graph2.line group02
'graph2.drawdefault linecolor(@RGB(200, 200, 200)) width(.25)  existing
for !i=1 to k_max
  graph2.setelem(!i) lcolor(@RGB(200, 200, 200)) 
next
graph2.setelem(251) lcolor(red) 
graph2.setelem(252) lcolor(red) 
graph2.setelem(253) lcolor(red) 
graph2.setelem(254) lcolor(blue) 

endsub
call oos_forec_ex

