Converting a stata code into eviews

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 a stata code into eviews

Postby Fregensburg » Tue Jan 21, 2014 4:36 am

Dear Sir/Madam,

I obtained this piece of Stata code from the authors of ‘What does the yield curve tell us about exchange rate predictability’.

I'm fine with most of the code, the remaining bit -which is a standalone part of the paper- is where I got stuck, and I was hoping you could give me a hand with it.

There have been several requests on the forum about the Nelson-Siegel model -the code below is precisely that0, so I think this will be very useful to other users (and pacify them).
I’ve include in squared brackets info on what the adjacent Stata commands do, but I presume you know that programming language already.

Lastly, this program was written for monthly data- how would the NS1 and NS2 have to be amended to handle weekly data (presumably the parameter 0.0609, which is from Diebold and Li 2006 would have to be re-estimated separately)?

Here it is:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
clear
#delimit;

(resets the character that marks the end of a command [assigns a semicolon to denote the end of a line]

set more 1;

[tells Stata not to wait for keyboard input before waiting to display the next screen of output -- you will not be able to read what Stata is doing as it scrolls by, but you can read the output in the log file.]

capture log close; [close a log if any is open and do nothing if no log is open]

set mem 400m;
set matsize 800; [sets the max amount of variables in the estimation]

use yields_data.dta, replace;

gen number=_n; [generates a number whose value is the sequential order of the observation in the dataset, starting from 1 from the Nst observation. _n is often used to generate unique codes for each observation]


reshape long y ycan yuk yjp, i(number) j(month);

[takes wide data files and reshapes them into long form]



gen level_ns=0;
gen slope_ns=0;
gen curvature_ns=0;
gen level_se_ns=0;
gen slope_se_ns=0;
gen curvature_se_ns=0;
gen r2_ns = 0;


gen diff=y-yuk;

gen ns1 =1;

gen ns2 = (1-exp(-0.0609*month))/(0.0609*month);

gen ns3 = (1-exp(-0.0609*month))/(0.0609*month) -exp(-0.0609*month);



foreach x of numlist 1/240 {;

regress diff ns1 ns2 ns3 if number==`x', robust noconstant ;
replace level_ns = _b[ns1] if number==`x';
replace slope_ns = _b[ns2] if number==`x';
replace curvature_ns = _b[ns3] if number==`x';
replace level_se_ns = _se[ns1] if number==`x';
replace slope_se_ns = _se[ns2] if number==`x';
replace curvature_se_ns = _se[ns3] if number==`x';
replace r2_ns = e(r2_a) if number==`x';
};

drop ns1 ns2 ns3;

reshape wide diff y ycan yuk yjp , i(number) j(month);


outsheet using NS_factors, replace;
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Any help with this would be much appreciated.

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

Re: Converting a stata code into eviews

Postby EViews Glenn » Tue Jan 21, 2014 10:44 am

Looks as though they are simply stacking all of the variables, then running the regression for each block in the stacked data (corresponding to an original observation), and assigning back the coefficients to the block and unstacking.

Should be pretty straightforward. How are your data currently stored?

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

Re: Converting a stata code into eviews

Postby Fregensburg » Wed Jan 22, 2014 4:29 am

Hi,

I've attached the author's data, as converted from their stata dta file.
I'm still at a loss in terms of translating this into eviews language, so I would appreciate any guidance on how to go about this, in terms of appropriate coding (if and when you have a spare minute).

Maybe it's just beginner's clumsiness, but my pride in writing up macro models has just been eclipsed by the mysteries of speaking software. Hats off to econometricians.

Many thanks
Attachments
Yields_data.xls
(300 KiB) Downloaded 604 times

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

Re: Converting a stata code into eviews

Postby EViews Glenn » Wed Jan 22, 2014 11:15 am

You don't have a month variable in that dataset. That variable seems to be used in the reshaping to long. Do you have the original .dta file?

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

Re: Converting a stata code into eviews

Postby Fregensburg » Wed Jan 22, 2014 1:07 pm

I do, but I don't seem able to attach it (extension dta is not allowed). How shall I get it to you?

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

Re: Converting a stata code into eviews

Postby EViews Glenn » Wed Jan 22, 2014 3:01 pm

Mail to support@eviews.com, reference the forum post, and ask that it be forwarded to me. I'm going to be in and out of the office for a day or so, so it may take me a bit before I can look at it.

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

Re: Converting a stata code into eviews

Postby Fregensburg » Mon Jan 27, 2014 12:38 am

I sent it through to support@estima.

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

Re: Converting a stata code into eviews

Postby EViews Glenn » Mon Jan 27, 2014 2:09 pm

I hope you didn't send it to support@estima since that will go to the RATS people :)

As you will see, the translation is pretty straightforward. There were a couple of idioms that had to be replaced, but other than that, it's just a bit of substituted commands...

Code: Select all

wfopen yields_data.dta pagestack(page=stacked) yjp? series number = id01 series month = var01 ' new series series level_ns = 0 series slope_ns = 0 series curvature_ns = 0 series level_se_ns = 0 series slope_se_ns = 0 series curvature_se_ns = 0 series r2_ns = 0 ' series of interest series diff = y - yuk series ns1 = 1 series ns2 = (1-exp(-0.0609*month))/(0.0609*month) series ns3 = (1-exp(-0.0609*month))/(0.0609*month)-exp(-0.0609*month) ' loop over values for !i = 1 to 240 ' set the subsample smpl if id01 = !i ' estimate the equation equation temp.ls(cov=white) diff ns1 ns2 ns3 ' assign the results level_ns = temp.c(1) slope_ns = temp.c(2) curvature_ns = temp.c(3) level_se_ns = temp.@stderrs(1) slope_se_ns = temp.@stderrs(2) curvature_se_ns = temp.@stderrs(3) r2_ns = temp.@r2 next ' unstack the page and copy into original page pageunstack(page=temp) var01 id01 @ *_ns pageselect yields_data copy temp\*_ns ' cleanup pagedelete temp

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

Re: Converting a stata code into eviews

Postby Fregensburg » Tue Jan 28, 2014 2:27 pm

ah! you know, long day at work.
glenn, you're a dude, thanks so much for that. it turns out that getting the relative slope with that procedure yields not a great improvement (in what i'm using it for) over a simple minded 10yr-3months differential between two countries, but nevermind, I learned some more eviews plus the model will be useful in other contexts.
I was just considering-in a parallel universe where people are actually paid their marginal product of labour, you and your eviews colleagues would be very, very wealthy individuals.
thanks again.

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

Re: Converting a stata code into eviews

Postby EViews Glenn » Tue Jan 28, 2014 3:23 pm

Thanks. Glad it helped.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests