Page 1 of 2

Matrix to Series

Posted: Fri Jun 18, 2010 8:56 am
by luching
How can I convert a matrix into a series? I tried using %pt, but it seems to work only when the matrix is a column matrix.

Re: Matrix to Series

Posted: Fri Jun 18, 2010 10:44 am
by TomDoan
What exactly are you trying to do? If you're trying to create series out of a column of a matrix, you can do

Code: Select all

set col1 1 %rows(matrix) = matrix(t,1)
set col2 1 %rows(matrix) = matrix(t,2)
etc.

If you're trying to create a whole collection of series that way, you can do:

Code: Select all

dec vect[series] cols(%cols(matrix))
do i=1,%cols(matrix)
   set col(i) 1 %rows(matrix) = matrix(t,i)
end do i

Re: Matrix to Series

Posted: Tue Jun 22, 2010 9:55 am
by luching
This is a piece of code I wrote to store a vector "shock" over loops of "ndraws" the counter being "accept"

compute capt=%rows(shock)
declare vect[vect] goodshock(ndraws)
dim goodshock(accept)(capt)
ewise goodshock(accept)(i)=shock(i)

This throws up an error. This must be trivial, but any thoughts? Thanks.

Re: Matrix to Series

Posted: Tue Jun 22, 2010 11:38 am
by TomDoan
Is shock your series? If so, the problem would be using %rows(shock). If it's defined from 1 to nstep (or something like that), just use capt=nstep.

Re: Matrix to Series

Posted: Tue Jun 22, 2010 12:44 pm
by luching
Shock is actually a matrix. So the error is not from %rows. The error message I got is

## SX20. Expected , Here
>>>>ept)(i)=shock(i)<<<<

Re: Matrix to Series

Posted: Tue Jun 22, 2010 5:55 pm
by TomDoan
If shock is an Nx1 matrix, you need to use shock(i,1), not just shock(i).

Re: Matrix to Series

Posted: Thu Jun 24, 2010 1:57 pm
by luching
Thanks. I did it this way, it works. I guess the one column matrix in "shock" must be taken as one "element" once I define goodshock as vect[vect]

declare vect[vect] goodshock(nkeep)
compute goodshock(accept+1) =shock

Re: Matrix to Series

Posted: Thu Jun 13, 2019 5:06 pm
by Esteban
Hi Tom,

I want to do exactly the opposite, I want to generate a matrix of 2x10, using the first 10 elements of two different series.

Re: Matrix to Series

Posted: Thu Jun 13, 2019 7:40 pm
by TomDoan
That's what the MAKE instruction is for.

Re: Matrix to Series

Posted: Sat Jun 15, 2019 9:52 am
by ateeb
I have made a matrix like

make x
# R to USM1

there are total of r variables that have been put into the matrix, now suppose i want to take out only the first series (complete) from first time period to the last and compute statistics on it or do any other operation on it, how can i index that?

Also if i want to take whole matrix or just one series from the matrix starting and ending on a different date than the complete matrix, how can i do that?

Like for example: I have total data from 2000:01 to 2010:12, i want to use whole matrix variables from 2001:02 to 2009:05 for regression then how would i use the matrix? or if i want to take out 1 series from matrix with that length how can i do that?

Regards,

Ateeb

Re: Matrix to Series

Posted: Sat Jun 15, 2019 9:58 am
by TomDoan
Why would you put it into a matrix only to use it as a series? Most of what you are talking about are calculations on series.

Re: Matrix to Series

Posted: Sat Jun 15, 2019 10:24 am
by ateeb
I personally think RATS is very complicated when it comes to saving something in an object and then calling it. However, can you help me with this:

lets consider i have variables R, M1 and LSM

I use the following command from user guide:

dofor i = r to LSM
set(scratch) i = log(i{0}/i{1})
end dofor

now in this i can understand that this is taking r to LSM and computing percentage change for each series, however, how can i see the output?

like in R software a person will know that an object was made say X which is a matrix and you can then do logged<-log(X) which saves a new matrix with all series logged, once done you can call out only the first series by typing logged[1].

So how can i now know which object contains the i that is done in the above loop in RATs and how can i call one of them and use it?

Regards,

Ateeb

Re: Matrix to Series

Posted: Sat Jun 15, 2019 10:31 am
by ateeb
I just finished chapter 1 of user guide and i am still not sure that once i read in the data, every variable is a series itself. I get that point, but now if i run a do loop transforming each of them and putting them in new variables or a matrix of variables?

The user guide or introduction does not help at all in understanding how i can create a space like columns for holding transformed variables.

If you can help, that will be great.

Regards,
Ateeb

Re: Matrix to Series

Posted: Sat Jun 15, 2019 12:19 pm
by TomDoan
ateeb wrote:I personally think RATS is very complicated when it comes to saving something in an object and then calling it.
A series IS an object, isn't it? That's the whole point---it represents a time series, which is a vector of data with a 1-1 relationship to time. A matrix object doesn't have that---the association of the element of the matrix with any given time period depends upon you handling it correctly. (And there have been papers done by very good, generally very careful researchers which have gotten that wrong and identified sample breaks at the wrong locations because of it).
ateeb wrote: However, can you help me with this:

lets consider i have variables R, M1 and LSM

I use the following command from user guide:

dofor i = r to LSM
set(scratch) i = log(i{0}/i{1})
end dofor

now in this i can understand that this is taking r to LSM and computing percentage change for each series, however, how can i see the output?
Depending upon what you want to see, PRINT or TABLE, e.g.

print / r to lsm

If you just want to see a subset (just to make sure it looks right), you can do something like

print * 10 r to lsm

ateeb wrote:=
like in R software a person will know that an object was made say X which is a matrix and you can then do logged<-log(X) which saves a new matrix with all series logged, once done you can call out only the first series by typing logged[1].
Which is useful if you want to convert everything, and not so useful if you have a mix of data---GDP is probably going to be in log or growth rates, interest rates probably go through as levels.
ateeb wrote: So how can i now know which object contains the i that is done in the above loop in RATs and how can i call one of them and use it?
I is the loop index. The first time through, it represents R, and is used to replace R with its growth rate. The second time through M1, and is used... Once the loop is done, it represents nothing, which is how loops (in any language) work. After your loop, you have three series R, M1 and LSM which are all in growth rates from the original data.

Re: Matrix to Series

Posted: Sat Jun 15, 2019 12:34 pm
by TomDoan
ateeb wrote:I just finished chapter 1 of user guide and i am still not sure that once i read in the data, every variable is a series itself. I get that point, but now if i run a do loop transforming each of them and putting them in new variables or a matrix of variables?

The user guide or introduction does not help at all in understanding how i can create a space like columns for holding transformed variables.

If you can help, that will be great.

Regards,
Ateeb
That's covered in

https://estima.com/docs/RATS 10 Introduction.pdf#page=33

You transform time series to other time series---sometimes to themselves, but usually to something with a different, more descriptive name.