New Series Based on an Existing Series and a Dummy Variable

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
alexecon
Posts: 72
Joined: Fri Oct 30, 2015 12:16 pm

New Series Based on an Existing Series and a Dummy Variable

Unread post by alexecon »

I have a series
  • x
    y
    z

and would like to set a new one
  • x
    x
    x

    y
    y
    y
    y

    z
    z

using an existing dummy
  • 1
    1
    1

    2
    2
    2
    2

    3
    3
How can I do this in RATS? Thank you.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: New Series Based on an Existing Series and a Dummy Varia

Unread post by TomDoan »

That looks like

set expanded = original(fix(dummy(t)))
alexecon
Posts: 72
Joined: Fri Oct 30, 2015 12:16 pm

Re: New Series Based on an Existing Series and a Dummy Varia

Unread post by alexecon »

TomDoan wrote:set expanded = original(fix(dummy(t)))
For some reason that is not immediately apparent to me this sets all values of expanded to 0 (even though original has nonzero values).
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: New Series Based on an Existing Series and a Dummy Varia

Unread post by TomDoan »

So far as I can tell, that should work fine based upon your definition. If you do

print 1 3 original

do you get the three values that you want?
alexecon
Posts: 72
Joined: Fri Oct 30, 2015 12:16 pm

Re: New Series Based on an Existing Series and a Dummy Varia

Unread post by alexecon »

TomDoan wrote:do you get the three values that you want?
Yes, I do get them. But I'm not sure why we are using fix in the first place. I was expecting we may need to use a loop that takes the first value (x) from the original series and copies it in the first three rows of the expanded series, then takes the second (y) value from the original and copies it in the next four rows of the expanded and so on.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: New Series Based on an Existing Series and a Dummy Varia

Unread post by TomDoan »

FIX is necessary because dummy(t) is a REAL and you need an INTEGER for a subscript. If the setup is as you describe it, what I provided will work. If it doesn't you'll have to post the actual program that you're trying to use.
alexecon
Posts: 72
Joined: Fri Oct 30, 2015 12:16 pm

Re: New Series Based on an Existing Series and a Dummy Varia

Unread post by alexecon »

Here is the code:

Code: Select all

OPEN DATA "/Users/[...].xls"
CALENDAR(D) 2001:1:1
DATA(FORMAT=XLS,ORG=COLUMNS) 2001:01:01 2014:12:31 XR3M XR0 RATE3M RATE USRATE USRATE3M

* set financial openness from daily data
set devcip_d = (1+usrate3m/100)-(1+rate3m/100)*(xr0/xr3m)
set fi_d = 1/exp((abs(devcip_d)))

* series transformations (growth rates)
dofor i = XR3M to USRATE3M
   compute [label] dlogs = "dl"+%l(i)
   set %s(dlogs) = log(i{0}/i{1})
 *  stats %s(dlogs)
enddofor i

* set monthly dummy and indicator from daily data
set yymm = %year(t)*100+%month(t)
panel(group=yymm,id=yymmvalues)

* set exchange rate stability (ers)
set mysd 1 %size(yymmvalues) = %na
do i=1,%size(yymmvalues)
   stats(noprint,smpl=(yymm==yymmvalues(i))) dlxr0
   compute mysd(i) = sqrt(%variance)
end do i
set mysd2 = mysd(fix(yymm(t)))
set ers = 1/(1+mysd2)
The frequency of the data in memory is daily. The last bit of the code calculates 168 monthly standard deviations from the daily data. My problem is that it stacks them at the beginning of the dataset as daily observations. What I am trying to do is to "expand" them so that there are 28/29/30 or 31 (identical) observations per month. (Then I can read the data into RATS compacted by monthly average, which is the setup that I eventually want to use).

Unfortunately, the line involving fix generates an empty series.

Image
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: New Series Based on an Existing Series and a Dummy Varia

Unread post by TomDoan »

The problem is that the "dummy" doesn't map to 1, 2, ... as it does in the simple example. The simplest way to do this is to use the SMPL option on SET. Just

Code: Select all

set yymm = %year(t)*100+%month(t)
panel(group=yymm,id=yymmvalues)
do i=1,%size(yymmvalues)
   stats(noprint,smpl=(yymm==yymmvalues(i))) dlxr0
   set(smpl=(yymm==yymmvalues(i))) mystd2 = sqrt(%variance)
end do i
Post Reply