converting ESTAR model written in RATS into eview-ese

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Fregensburg
Posts: 38
Joined: Tue Jan 21, 2014 4:04 am

converting ESTAR model written in RATS into eview-ese

Postby Fregensburg » Thu Apr 03, 2014 6:47 am

Hi,

I'm keen to mimick a model written by Shintani, M, Terada-Hagiwara, A and Yabu, T 'Exchange rate pass-through and inflation: a nonlinear time series analysis’ Journal of International Money and Finance 32 (2013). I've seen Trubador's LSTAR's sample code and I’ve followed his lead. It should be straightforward but I'm screwing something up.
I started off with their data in order to ensure I was getting it right. The data is attached to this post.
The authors provide the code, which you can find here (the comments are mine):

Code: Select all

***************************************************************** * This program is to estimate ESTAR ***************************************************************** CALENDAR 1975 1 12 ALLOCATE 2007:12 open data data.xls data(format=xls,org=columns) /* imp is the seasonally adjusted US import price index ppi is the seasonally adjusted US producer price index */ *variables used in the regressions* set p = ppi set s = imp set dp = 100*log(p/p{1}) set ds = 100*log(s/s{1}) ******* *ESTAR* 'why estar -reasonable to think there are costs of adjustment in either direction ******* 'the transition function is a moving average of 3 lags of producer price inflation set z = (dp{1}+dp{2}+dp{3})/3 STATISTICS(fractiles, noprint) z compute std = sqrt(%variance) set z_big = (z>%FRACT90)+(z<%FRACT10) 'z is the transition variable 'c is the threshold 'which one is the speed and smoothness parameter (is it gamma?) 'this sets free parameters for non linear estimation nonlin(paraset=base) c0 $ bp1 bp3 bp4 $ bs0 bs1 bs4 bs5 $ c0_out bp5_out $ bs2_out bs4_out gam 'gamma is the speed and smoothness parameter nonlin(paraset=const) gam>=0 frml estar1 = c0 $ +bp1*dp{1}+bp3*dp{3}+bp4*dp{4} $ +bs0*ds+bs1*ds{1}+bs4*ds{4}+bs5*ds{5} $ +(c0_out+bp5_out*dp{5} $ +(1-bs0)*ds+bs2_out*ds{2}+bs4_out*ds{4}) $ *(1-exp(-gam*(z/std)**2)) 'six lags of import prices times the transition function set ds_big = z_big*ds set ds_big1 = z_big*ds{1} set ds_big2 = z_big*ds{2} set ds_big3 = z_big*ds{3} set ds_big4 = z_big*ds{4} set ds_big5 = z_big*ds{5} set dp_big1 = z_big*dp{1} set dp_big2 = z_big*dp{2} set dp_big3 = z_big*dp{3} set dp_big4 = z_big*dp{4} set dp_big5 = z_big*dp{5} set dp_big6 = z_big*dp{6} 'now regress the producer price index on own lags, lags of import prices and the transition function(s). linreg(noprint) dp # constant dp{1 to 6} ds{0 to 5} $ ds_big ds_big1 ds_big2 ds_big3 ds_big4 ds_big5 $ dp_big1 dp_big2 dp_big3 dp_big4 dp_big5 dp_big6 compute c0=%beta(1), $ bp1=%beta(2), bp2=%beta(3), bp3=%beta(4), bp4=%beta(5), bp5=%beta(6), bp6=%beta(7),$ bs0=%beta(8), bs1=%beta(9),bs2=%beta(10), bs3=%beta(11),bs4=%beta(12),bs5=%beta(13), $ bs1_out=%beta(15), bs2_out=%beta(16), bs3_out=%beta(17), bs4_out=%beta(18), bs5_out=%beta(19), $ bp1_out=%beta(20), bp2_out=%beta(21), bp3_out=%beta(22), bp4_out=%beta(23), bp5_out=%beta(24), bp6_out=%beta(25), $ gam=1, c0_out=0 nlls(frml=estar1, paraset=base+const, iterations=300, method=gauss, subiterations=30, vcv) dp
And this is my not so successful attempt (I know the starting values I put down are arbitrary, but at this stage that's secondary ):

Code: Select all

'change path to program path %path = @runpath cd %path 'create workfile wfcreate JPNPT M 1975:1 2007:12 read(a2,s=basics) H:\NonlinearERPT\data.xls 2 series p = ppi series s = imp series dp = 100*d(log(p),0,1) series ds = 100*d(log(s),0,1) 'the transition variable z is the moving average of lagged producer price inflation series z = (dp(-1)+dp(-2)+dp(-3))/3 'create series with values in the 90th and above and in the 5th and below quantiles series z_big = @recode((z>@quantile(z, 0.90))+(z<@quantile(z,0.1)), z, NA) smpl @first @first series dpf = 1 'declare coefficients coef(1) c0 coef(1) bp1 coef(1) bp3 coef(1) bs4 coef(1) bs5 coef(1) c0_out coef(1) bp5_out coef(1) bs2_out coef(1) bs4_out coef(1) gam coef(1) sig 'starting values c0(1) = 1 bp1(1) = 1 c(1) = 1 bp1(1) = 1 bp3(1) =1 bs4(1) = 1 bs5(1) = 1 c0_out(1) = 1 bp5_out(1) = 1 bs2_out(1) = 1 bs4_out(1) = 1 gam = 10 sig(1) = 1 series ds_big = z_big*ds series ds_big1 = z_big*ds(-1) series ds_big2 = z_big*ds(-2) series ds_big3 = z_big*ds(-3) series ds_big4 = z_big*ds(-4) series ds_big5 = z_big*ds(-5) series dp_big1 = z_big*dp(-1) series dp_big2 = z_big*dp(-2) series dp_big3 = z_big*dp(-3) series dp_big4 = z_big*dp(-4) series dp_big5 = z_big*dp(-5) series dp_big6 = z_big*dp(-6) logl estar estar.append @logl logl estar.append dpf = c0 + bp1*dp(-1) + bp3*dp(-3) + bp4*dp(-4) + bs0*ds + bs1*ds(-1) + bs4*ds(-4) + bs5*ds(-5) + (c0_out + bp5_out*dp(-5) + (1-bs0)*ds + bs2_out*ds(-2) + bs4_out*ds(-4))*(1-exp(-gam*(z/(@stdev(z))^2) estar.append res =dp - dpf estar.append var = sig(1)^2 estar.append s = res/@sqrt(var) estar.append logl = log(@dnorm(s)) - log(var)/2 smpl @first+1 @last estar.ml(showopts, m=1000, c=1e-5) show estar.output smpl @all
Does anyone know how what the issues with my code are?
Attachments
data.xls
(40.5 KiB) Downloaded 519 times

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: converting ESTAR model written in RATS into eview-ese

Postby trubador » Thu Apr 03, 2014 7:12 am

The following are evident mistakes at first glance:
1) Coefficient syntax in formulas are wrong (e.g. use c0(1) instead of c0)
2) Coefficents bp4, bs0 and bs1 are missing.
3) There are unmatched parentheses in dpf = ....
4) Carefully adjust your sample period

Fregensburg
Posts: 38
Joined: Tue Jan 21, 2014 4:04 am

Re: converting ESTAR model written in RATS into eview-ese

Postby Fregensburg » Thu Apr 03, 2014 7:44 am

Hi Trubador,

many thanks for your suggestions, I addressed the first three, but I'm unsure about how to set the sample size appropriately. Currently I get a missing values etc etc error message once the maximum likelihood line is reached -and it probably has got something to do for me not accounting for the 6 lags properly. May I ask you to pinpoint how and where to adjust the samples?

The revised code:
'change path to program path
%path = @runpath
cd %path
'create workfile

wfcreate JPNPT M 1975:1 2007:12
read(a2,s=basics) H:\NonlinearERPT\data.xls 2

series p = ppi
series s = imp
series dp = 100*d(log(p),0,1)
series ds = 100*d(log(s),0,1)

'the transition variable z is the moving average of lagged producer price inflation
series z = (dp(-1)+dp(-2)+dp(-3))/3

'create series with values in the 90th and above and in the 5th and below quantiles
series z_big = @recode((z>@quantile(z, 0.90))+(z<@quantile(z,0.1)), z, NA)

smpl @first @first
series dpf = 1

'declare coefficients
coef(1) c0
coef(1) bp1
coef(1) bp3
coef(1) bp4
coef(1) bs0
coef(1) bs1
coef(1) bs4
coef(1) bs5
coef(1) c0_out
coef(1) bp5_out
coef(1) bs2_out
coef(1) bs4_out
coef(1) gam
coef(1) sig
'starting values from AR
c0(1) = 1
bp1(1) = 1
bp3(1) = 1
bp4(1) = 1
bs0(1) = 1
bs1(1) = 1
bs4(1) = 1
bs5(1) = 1
c0_out(1) = 1
bp5_out(1) = 1
bs2_out(1) = 1
bs4_out(1) = 1
gam(1) = 10
sig(1) = 1

series ds_big = z_big*ds
series ds_big1 = z_big*ds(-1)
series ds_big2 = z_big*ds(-2)
series ds_big3 = z_big*ds(-3)
series ds_big4 = z_big*ds(-4)
series ds_big5 = z_big*ds(-5)
series dp_big1 = z_big*dp(-1)
series dp_big2 = z_big*dp(-2)
series dp_big3 = z_big*dp(-3)
series dp_big4 = z_big*dp(-4)
series dp_big5 = z_big*dp(-5)
series dp_big6 = z_big*dp(-6)

smpl @all
logl estar
estar.append @logl logl
estar.append dpf = c0(1) + bp1(1)*dp(-1) + bp3(1)*dp(-3) + bp4(1)*dp(-4) + bs0(1)*ds + bs1(1)*ds(-1) + bs4(1)*ds(-4) + bs5(1)*ds(-5) + (c0_out(1) + bp5_out(1)*dp(-5) + (1-bs0(1))*ds + bs2_out(1)*ds(-2) + bs4_out(1)*ds(-4))*(1-exp(-gam(1)*(z/(@stdev(z)))^2))
estar.append res =dp - dpf
estar.append var = sig(1)^2
estar.append s = res/@sqrt(var)
estar.append logl = log(@dnorm(s)) - log(var)/2

smpl @first+1 @last
estar.ml(showopts, m=1000, c=1e-5)
show estar.output

smpl @all

Fregensburg
Posts: 38
Joined: Tue Jan 21, 2014 4:04 am

Re: converting ESTAR model written in RATS into eview-ese

Postby Fregensburg » Thu Apr 03, 2014 8:38 am

I've seen other posts concerning the 'missing values at current coefficient values, etc' error message with this type of models, so perhaps this isn't to do with the samples I set. The programmers' response to those posts has been to try different starting values -I've just spent half an hour trying that out, to no avail. Does anyone have any solution other than what I've already done? This model can be estimated- the results are published, so there has to be a way to handle it.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: converting ESTAR model written in RATS into eview-ese

Postby EViews Glenn » Thu Apr 03, 2014 9:40 am

I'm not certain what you are trying to do with the lines

Code: Select all

smpl @first @first series dpf = 1
which set the first observation of your dependent variable to 1. This operation looks somewhat dodgy to me, and I suspect that it isn't what you really want to do.

More importantly, Trubador's original advice on looking at the sample is, as usual, on the mark. Your specification for the likelihood has a number of lags in it which generate missing observations. Notably, the explanatory variable DP(-5) is the 5-th lag of a DLOG and is therefore missing for the first 6 observations of the workfile. If you try to estimate the likelihood over the sample from 2 to 396 as you have done, observations 2-6 cannot be evaluated no matter what starting values you choose. Note that EViews tells you the observation in which the missing was found. Looking at the values of DPF, RES, VAR, S, and LOGL at that observation should pretty quickly show you what's up.

Setting the sample to 7 396 generates results, though I don't know whether they match the results of interest.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest