Page 1 of 1

New Series Based on an Existing Series and a Dummy Variable

Posted: Fri Dec 25, 2015 6:47 pm
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.

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

Posted: Fri Dec 25, 2015 9:25 pm
by TomDoan
That looks like

set expanded = original(fix(dummy(t)))

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

Posted: Sat Dec 26, 2015 7:13 am
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).

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

Posted: Sat Dec 26, 2015 3:36 pm
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?

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

Posted: Sun Dec 27, 2015 4:26 am
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.

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

Posted: Sun Dec 27, 2015 10:00 am
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.

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

Posted: Sun Dec 27, 2015 11:32 am
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

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

Posted: Sun Dec 27, 2015 12:14 pm
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