Page 1 of 1

means of panel data and sorting in table

Posted: Wed Oct 31, 2012 7:23 am
by neptunhiker
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.

Re: means of panel data and sorting in table

Posted: Wed Oct 31, 2012 9:33 am
by EViews Gareth
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.

Re: means of panel data and sorting in table

Posted: Wed Oct 31, 2012 9:58 am
by neptunhiker
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.

Re: means of panel data and sorting in table

Posted: Wed Oct 31, 2012 10:11 am
by EViews Gareth

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

Re: means of panel data and sorting in table

Posted: Wed Oct 31, 2012 11:17 am
by neptunhiker
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?

Re: means of panel data and sorting in table

Posted: Wed Oct 31, 2012 11:30 am
by EViews Gareth
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

Re: means of panel data and sorting in table

Posted: Wed Oct 31, 2012 1:09 pm
by neptunhiker
Hi Gareth,

thank you very much. Perfect!