Several observations per line

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

paues
Posts: 218
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Several observations per line

Postby paues » Fri Aug 31, 2012 12:51 am

I have a tab-separated text file containing a heap of quarterly series which are stored as a matrix. The columns contain the following information:

1. YEAR (contains value for all lines)
2. Part one of series name (contains value for all lines)
3. Part two of series name (contains value for some lines)
4. Value for first quarter (contains value for all lines)
5. Value for second quarter (contains value for all lines)
6. Value for third quarter (contains value for all lines) and
7. Value for fourth quarter (contains value for all lines)

I would like to (A) import the text file; (B) concatenate the series-name parts to one column, replacing all NA from column three with the string ""; and (C) unstack the matrix to get the quarterly series.

What I have so far is:

Code: Select all

wfopen(type=text,wf=tmp,page=matrix) C:\...\exampledata.txt names=(year, name01, name02, q1, q2, q3, q4) delim=tab pagestruct(none) alpha name=name01 + @str(name02) delete name01 name02 pagestruct name @date(year)
Attachments
exampledata.txt
(181 Bytes) Downloaded 517 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Several observations per line

Postby EViews Gareth » Fri Aug 31, 2012 7:58 am

Tricky.

Code: Select all

wfopen(type=text) exampledata.txt names=(year, name01, name02, q1, q2, q3, q4) delim=tab alpha name = name01+@str(name02) pagestruct name @date(year) delete name01 name02 pagestack q? alpha date = @str(year) + "q" + @str(var01) pagestruct @date(date) name d dateid var01 rename q data pageunstack name date pagestruct @date(date) d data date dateid01 name year rename data* *

paues
Posts: 218
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Re: Several observations per line

Postby paues » Mon Sep 03, 2012 1:20 am

Brilliant! That was much more straightforward than the approach I was trying. With this fixed there is the issue of giving the series more sensible names. I have another file (attached) which contains three columns:

1. part one of series name (same as column 2 in exampledata.txt),
2. part two of series name (same as column 3 in exampledata.txt), and
3. final series name.

How would one go about to map these to the matrix found in exampledata.txt and give the alpha series "name" the values specified in column 3 of examplemap.txt instead?
Attachments
examplemap.txt
(21 Bytes) Downloaded 566 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Several observations per line

Postby EViews Gareth » Tue Sep 04, 2012 9:48 am

Code: Select all

wfopen(type=text) exampledata.txt names=(year, name01, name02, q1, q2, q3, q4) delim=tab alpha name = name01+@str(name02) pagestruct name @date(year) delete name01 name02 pagestack q? alpha date = @str(year) + "q" + @str(var01) pagestruct @date(date) name d dateid var01 rename q data pageunstack(page=mypage) name date pagestruct @date(date) d data date dateid01 name year rename data* * pageload examplemap.txt !length = @obsrange alpha name = series01 + @str(series02) table names for !i=1 to !length names(!i,1) = name(!i) names(!i,2) = series03(!i) next copy names mypage\names pagedelete examplemap pageselect mypage for !i=1 to !length %name1 = names(!i,1) %name2 = names(!i,2) rename {%name1} {%name2} next

paues
Posts: 218
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Re: Several observations per line

Postby paues » Fri Dec 21, 2012 7:01 am

I have discovered another problem with this issue. In the attached workfile I have two pages (named one and two). Each page holds a 6-dimensional panel that in the end should be transformed to quarterly series (as per my initial post here above).

1. NAME (what the final quarterly series should be called)
2. YEAR
3. Q1 (series NAME's value for the first quarter in each YEAR)
4. Q2 (series NAME's value for the second quarter in each YEAR)
5. Q3 (series NAME's value for the third quarter in each YEAR)
6. Q4 (series NAME's value for the fourth quarter in each YEAR)

In line with suggestions from Gareth (in the second post in this topic) I have written the following code.

Code: Select all

for %pg one two pageselect exampledata\{%pg} pagestruct name @date(year) pagestack q? alpha date=@str(year)+"Q"+@str(var01) pagestruct @date(date) name delete dateid var01 pageunstack name date pagestruct @date(date) delete q date dateid01 name year next
However, page two returns an error ('Illegal panel structure DATEID is nested within NAME in "PAGESTRUCT NAME @DATE(YEAR)".') - from what I can tell relating to the fact that all the values in page two are for the year 2012. This however should not be a problem and I am inclined to see this as a bug. Do you have any suggestions for how I should create my quarterly series from the pages one and two?
Attachments
exampledata.WF1
(170.73 KiB) Downloaded 408 times

paues
Posts: 218
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Re: Several observations per line

Postby paues » Fri Dec 21, 2012 8:27 am

While the bug report from my previous post still stands (it SHOULD be possible to execute the line "pagestruct name @date(year)" even if the YEAR series contains only one value), I have found an alternative approach which, while not as elegant, does the trick:

Code: Select all

for %pg one two pageselect {%pg} %original=@pagename for !i=1 to 4 pageselect {%original} pagecopy(page={%pg}q{!i}) alpha date=@str(year)+"q"+@str(!i) rename q{!i} q delete(noerr) q1 q2 q3 q4 next pageselect {%pg}q1 for !i=2 to 4 pageappend {%pg}q{!i} pagedelete {%pg}q{!i} next pageselect {%pg}q1 delete year pagestruct @date(date) name delete dateid pageunstack(page={%pg}series) name date pagestruct @date(date) delete q date dateid name rename q* * delete(noerr) obsid next

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

Re: Several observations per line

Postby EViews Glenn » Fri Dec 21, 2012 11:37 am

To be a valid panel structure in EViews you need two things:

1. The cross-section and within cross-section identifiers should jointly identify a unique observation.
2. There should be at least one cross-section with more than one observation.

The first is satisfied by your data, the second is not. Basically, the year dimension doesn't add identifying information so you have a data set that is more accurately classified as a cross-section workfile.

Now as your statement that it *should* be possible to classify this as a panel workfile. I am curious as to what the purpose of doing might be since there really isn't a panel.

paues
Posts: 218
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Re: Several observations per line

Postby paues » Thu Jan 10, 2013 4:59 am

Please excuse my tardiness. I see that I might be somewhat oblivious regarding the panel concept. Maybe my problem would be solved if I included a series containing observation number? (I would try it myself, but I do not have access to EViews right now, as I am on leave.)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests