means of panel data and sorting in table

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason

neptunhiker
Posts: 50
Joined: Sat Oct 20, 2012 7:30 am

means of panel data and sorting in table

Postby neptunhiker » Wed Oct 31, 2012 7:23 am

Hi everyone,

I am working with panel data and I would like to calculate means for each of the crosssections for two different series. This is my solution:

Code: Select all

series meansby1=@meansby(series1,id) series meansby2=@meansby(series2,id)
If each of my series had data for 3 different crosssections, I would get 6 means (3 means for 3 crosssections in series1 and 3 means for 3 crosssections in series2).
Since I would like to compare the means with each other, I open each of the series individually and then use view-descriptive statistics & test-stats by classification to bring up a table that shows the calculated means by id (since I put in "id" in the input field "series/group for classify" in the "statistics by classification" window).

That works ok, but I would like to compare the data in one table (first problem) and sort the means not by id but by the occurence of the crosssections in the original series (second problem).

To summarize: Is there a way to use the @meansby function, in order to compare the means of crosssections of different series in one single table and how can I sort the output by the occurence of the crosssections in the original series?

Thanks a lot in advance for suggestions and help.

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

Re: means of panel data and sorting in table

Postby EViews Gareth » Wed Oct 31, 2012 9:33 am

I'm not entirely sure I follow your issues, but unless you have a huge number of cross-sections, you're probably better off doing it in a pooled workfile, rather than a panel. Comparing cross-id means in a pooled workfile is much easier.

neptunhiker
Posts: 50
Joined: Sat Oct 20, 2012 7:30 am

Re: means of panel data and sorting in table

Postby neptunhiker » Wed Oct 31, 2012 9:58 am

Hi Gareth,

I will have between 100 and 200 crosssections, therefore a panel structure is probably still best, don't you think?

Just to clarify my problem. I would like to calculate the means of every crosssection in my workfile. The crosssections are stored in different series. The calculation of means is not the problem, I managed to do that via the @meansby function as shown in my previous post. The only thing that I seem not to be able to handle is to create a table which contains all the means categorized by cross section and series.

I have attached an example of a table that I would like to produce in eViews. Maybe that helps to describe my question.
Attachments
meansby.pdf
(5.84 KiB) Downloaded 525 times

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

Re: means of panel data and sorting in table

Postby EViews Gareth » Wed Oct 31, 2012 10:11 am

Code: Select all

'create a panel with 4 ID series - A, B, C, D create a 1990 2020 4 alpha id = "A" smpl if @crossid=2 id = "B" smpl if @crossid=3 id = "C" smpl if @crossid=4 id = "D" pagestruct @date(dateid) id delete crossid 'make some data series series series1=nrnd series series2 = nrnd series series3 = nrnd '-------------------------------------------------------------------- 'freeze the statsby classification table of each freeze(tab1) series1.statby(nostd, nocount) id freeze(tab2) series2.statby(nostd, nocount) id freeze(tab3) series3.statby(nostd, nocount) id 'make parent table table mytab 'copy tab1 into mytab tab1.copyrange a7 b11 mytab a1 'copy tab2 into mytab tab2.copyrange b7 b11 mytab c1 'copy tab3 into mytab tab3.copyrange b7 b11 mytab d1 'change headers mytab(1,2) = "series1" mytab(1,3) = "series2" mytab(1,4) = "series3" show mytab

neptunhiker
Posts: 50
Joined: Sat Oct 20, 2012 7:30 am

Re: means of panel data and sorting in table

Postby neptunhiker » Wed Oct 31, 2012 11:17 am

Hi Gareth,

amazing how easy it works out when you do it. You helped me a lot with this complete solution at least for my first problem. The second problem still seems to be unsolved.
In your solution it doesn't appear, because you have named the IDs alphabetically. If you look at the following program, you might understand my problem. I have only changed the naming of the ID series.

Code: Select all

'create a panel with 4 ID series - A, B, C, D create a 1990 2020 4 alpha id = "A1" smpl if @crossid=2 id = "A4" smpl if @crossid=3 id = "A3" smpl if @crossid=4 id = "A2" pagestruct @date(dateid) id delete crossid 'make some data series series series1=nrnd series series2 = nrnd series series3 = nrnd '-------------------------------------------------------------------- 'freeze the statsby classification table of each freeze(tab1) series1.statby(nostd, nocount) id freeze(tab2) series2.statby(nostd, nocount) id freeze(tab3) series3.statby(nostd, nocount) id 'make parent table table mytab 'copy tab1 into mytab tab1.copyrange a7 b11 mytab a1 'copy tab2 into mytab tab2.copyrange b7 b11 mytab c1 'copy tab3 into mytab tab3.copyrange b7 b11 mytab d1 'change headers mytab(1,2) = "series1" mytab(1,3) = "series2" mytab(1,4) = "series3" show mytab
When you open a series, you will see that the crosssections are in the order A1, A4, A3 and then A2. But when you look at the "mytab" table, you will see that the means of the crosssections are ordered alphabetically, i.e. A1, A2, A3 and then A4. That doesn't seem like a big issue, but imagine you had 100-200 crosssections with IDs looking like that "90w390njsd". It would be a real pain to put them back in the order of their appearance in their original series manually, right? So, is there a way to keep the order of original appearance in "mytab" instead of the alphabetical order?

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

Re: means of panel data and sorting in table

Postby EViews Gareth » Wed Oct 31, 2012 11:30 am

Use a valmap:

Code: Select all

'create a panel with 4 ID series - A, B, C, D create a 1990 2020 4 alpha id = "A1" smpl if @crossid=2 id = "A4" smpl if @crossid=3 id = "A3" smpl if @crossid=4 id = "A2" pagestruct @date(dateid) id delete crossid 'make some data series series series1=nrnd series series2 = nrnd series series3 = nrnd '-------------------------------------------------------------------- 'make a value map to maintain sort order id.makemap(nosort) mymapid mymap 'freeze the statsby classification table of each freeze(tab1) series1.statby(nostd, nocount) mymapid freeze(tab2) series2.statby(nostd, nocount) mymapid freeze(tab3) series3.statby(nostd, nocount) mymapid 'make parent table table mytab 'copy tab1 into mytab tab1.copyrange a7 b11 mytab a1 'copy tab2 into mytab tab2.copyrange b7 b11 mytab c1 'copy tab3 into mytab tab3.copyrange b7 b11 mytab d1 'change headers mytab(1,2) = "series1" mytab(1,3) = "series2" mytab(1,4) = "series3" show mytab

neptunhiker
Posts: 50
Joined: Sat Oct 20, 2012 7:30 am

Re: means of panel data and sorting in table

Postby neptunhiker » Wed Oct 31, 2012 1:09 pm

Hi Gareth,

thank you very much. Perfect!


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests