Read dataset with mixed string and number

For questions and discussion related to reading in and working with data.
BinhPham
Posts: 51
Joined: Tue Feb 14, 2017 10:00 am

Read dataset with mixed string and number

Unread post by BinhPham »

Dear Tom,

I've got trouble with RATS read data process. My panel data has all numeric columns from 2nd to the end but the first one is a string as it is "country name". Of course I can omit the first one but I want to retain it because I import directly from STATA dataset.

RATS cannot read the first column correctly as it always reports error for the first, but nothing for the remains.

Code: Select all

OPEN DATA "H:\RATS_codes\Asean6.dta"
CALENDAR(PANELOBS=46,A) 1970:1
DATA(FORMAT=DTA) 1//1970:01 8//2015:01 country year f_cons h_cons g_cons gr_cap $ 
gf_cap chg_inv exports imports  rgdp rgdp_agri rgdp_mining rgdp_manu rgdp_const $
rgdp_trade rgdp_trans rgdp_others tv_added pop cnt_id  tb xmy
Could you explain me why it is so! And how to solve this problem?

Thanks in advance,
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Read dataset with mixed string and number

Unread post by TomDoan »

Add the LEFT=2 option to the DATA instruction.
BinhPham
Posts: 51
Joined: Tue Feb 14, 2017 10:00 am

Re: Read dataset with mixed string and number

Unread post by BinhPham »

Thank you a lot, Tom!

Could I ask a simple question!?

As my panel have 8 cross-sectional units and I want to loop over individual. I write code as below:

Code: Select all

do ii=1,8
   smpl ii//1986:1 ii//2015:1
   linreg y
   # constant ltrend ltrend2
end do
I also want to get residuals each run of LINREG and store to a matrix say size of N by T. It is easy in Matlab or STATA but I am confusing with RATS variable declaration and usage.

The similar thing is filtering individual series then store cyclic components in a matrix N by T to graph them.

Could you do me a favor ?

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

Re: Read dataset with mixed string and number

Unread post by TomDoan »

The SMPL instruction is usually not the best choice for something like that (mainly because you have to take the extra step of disabling it with an empty SMPL instruction when you're done). Instead

linreg(smpl=%indiv(t)==ii) y
# constant ltrend ltrend2

does the same thing without side-effects.

MAKE with the PANEL option can be used to create a matrix from a series with the panel data blocking.
BinhPham
Posts: 51
Joined: Tue Feb 14, 2017 10:00 am

Re: Read dataset with mixed string and number

Unread post by BinhPham »

Perfect, Tom.

Thanks a lot. RATS is very powerful but it's also complicated!
BinhPham
Posts: 51
Joined: Tue Feb 14, 2017 10:00 am

Re: Read dataset with mixed string and number

Unread post by BinhPham »

Hi Tom,

Sorry to ask you again!

I have extracted a matrix from series using MAKE.

But, command like FILTER or most of commands only work with series. How can I transform Matrix back to Series?

As previous post, I extract a panel of individual ii => a matrix of T by K. Now I want to apply HP filter on each column. If I work with series, I then have to SMPL to unit ii before filtering but the filtered results would be the series with defined panel range.

That's a reason I only extract a panel I want to work with and don't touch on anything else. I read the manual and user-guide and see nothing about datatype conversion!

Waiting for your help, thanks!
Post Reply