Page 1 of 2

Conditional mean

Posted: Wed Apr 16, 2014 9:26 am
by kirill.serykh
Hello, guys. I have 2 problems, can you please help me to solve them?
First of all, I have a data set from PISA which contains results of mathematical tests of different puupils from different schools from different countries. This list contains 34 countries, 5 periods of time, huge number of schools from every country and more huge numberof pupils. There are 2 separate variables for country and year: - CNT (where there is a 3-digit text code for the country, for example, AUS, USA, RUS...) and YEAR - where is a year (2000, 2003, 2006, 2009, 2012). So, here are my 2 problems:
1) I have 30 other variables for which I want to calculate a mean value for each country in each year.
2) Also I have a school ID variable and a couple of school data variables that are repeated for each pupil that belongs to the current school. I need to calculate the conditional mean data for each year and country, but due to the fact that for pupils from one school data are the same, I need to delete all data for that school except one.
How can I do this in Eviews?

Re: Conditional mean

Posted: Wed Apr 16, 2014 9:29 am
by EViews Gareth
1) Open a series, click on View->Descriptive Statistics->Stats By Classification, and enter "year country" as the series to classify by.

2) We'd need to see the workfile to get an idea of how your data is structured.

Re: Conditional mean

Posted: Wed Apr 16, 2014 10:23 am
by kirill.serykh
2) We'd need to see the workfile to get an idea of how your data is structured.
Here is the file data.f1
For instance, there is only one year, but 34 countries. I need an average value of pvscie1 for every school in every country, but there is a problem: sometimes schoolid data are the same for different schools in different countries ( for example, schoolid has a value 6 for AUT and for LVA, but these schools are different.

Re: Conditional mean

Posted: Wed Apr 16, 2014 10:24 am
by kirill.serykh
1) Open a series, click on View->Descriptive Statistics->Stats By Classification, and enter "year country" as the series to classify by.
And is it possible to do such operation for the group of variables? Of course, it's possible to repeat this operation for 30 times, but it's a little bit time-wasting :(

Re: Conditional mean

Posted: Wed Apr 16, 2014 10:26 am
by EViews Gareth
Same procedure, but enter "schoolid cnt" as the series to classify by.

Re: Conditional mean

Posted: Wed Apr 16, 2014 12:08 pm
by kirill.serykh
Thank you so much. And I have one more question: what if need an average value by all schools in the country? The problem is that actually, I need only one observation of variables PCGIRLS and COMPWEB for each school of each country, because values of these variables are repeated for every observation (pupil) in every school. How is possible to leave only one value for each school and to delete others?

Re: Conditional mean

Posted: Wed Apr 16, 2014 12:59 pm
by EViews Gareth
1) Open a series, click on View->Descriptive Statistics->Stats By Classification, and enter "year country" as the series to classify by.
And is it possible to do such operation for the group of variables? Of course, it's possible to repeat this operation for 30 times, but it's a little bit time-wasting :(
Write a for loop that loops through the elements of the group and uses the @meansby function, or the series.statsby command. More details can be found in the Command and Programming Reference, and the Object Reference.

Re: Conditional mean

Posted: Wed Apr 16, 2014 1:00 pm
by EViews Gareth
Thank you so much. And I have one more question: what if need an average value by all schools in the country? The problem is that actually, I need only one observation of variables PCGIRLS and COMPWEB for each school of each country, because values of these variables are repeated for every observation (pupil) in every school. How is possible to leave only one value for each school and to delete others?
We'd need to see the workfile.

Re: Conditional mean

Posted: Wed Apr 16, 2014 1:18 pm
by kirill.serykh
Thank you so much. And I have one more question: what if need an average value by all schools in the country? The problem is that actually, I need only one observation of variables PCGIRLS and COMPWEB for each school of each country, because values of these variables are repeated for every observation (pupil) in every school. How is possible to leave only one value for each school and to delete others?
We'd need to see the workfile.
Here it is, I'm sorry.

Re: Conditional mean

Posted: Wed Apr 16, 2014 1:27 pm
by EViews Gareth
Something like:

Code: Select all

smpl if @trend=0 or (schoolid<>schoolid(-1)) show @mean(pcgirls)

Re: Conditional mean

Posted: Wed Apr 16, 2014 2:05 pm
by kirill.serykh
It shows only one value for all observations.

Re: Conditional mean

Posted: Wed Apr 16, 2014 2:09 pm
by EViews Gareth
There is only one mean...

Re: Conditional mean

Posted: Wed Apr 16, 2014 2:14 pm
by kirill.serykh
Oh, I'm sorry, maybe I said not very correctly.
I meant that I need 34 means, where 34 is the number of countries. The problem is that data are available for every pupil, but pupils that are studying in one school have the same data (like, PCGIRLS = percentage of girls, and the percentage of girls is the same in each school for every pupil). The problem is that I need to leave only one row for every school (because they are repeated) and then to calculate mean for every country.

Re: Conditional mean

Posted: Wed Apr 16, 2014 2:19 pm
by EViews Gareth
ok, so set the sample like I said, then do the @meansby, or View->Descp Stats->Stats by Classification

Re: Conditional mean

Posted: Wed Apr 16, 2014 2:31 pm
by kirill.serykh
But it's still shows me only one value for all of the schools in all countries - 260.5809
I meant that I need to delete all the repeated values, for instance, first 16 values are 0.510, but I need to leave only one (because this is the value for school, not for the pupil), and then to calculate average value for the country.