Hi all!
I'm using EViews 7 and I have a panel workfile containing data for different countries. I would like to get the weighted mean of a variable across time using population weights. There is a way to construct this variable and to see it in a spreadsheet?
I know I can use
View->Descriptive Statistics->Stats by Classification, but I can’t find the way to use population weights!
I’m sorry if this is a stupid question, but I’m new to E views!
Thanks a lot,
Valentina
weighted mean- country panel data
Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: weighted mean- country panel data
Can you describe your structure in a bit more detail. There are a couple dimensions to keep track of and it's not clear (at least to me), which dimension is which...Do you have cross-section population weights and want to compute a weighted mean over both time *and* cross-section? Or weighted means for each cross-section? In the latter case, what do the population weights vary over?
Re: weighted mean- country panel data
Sorry if I have not been so clear (and if my English is not very good).
My workfile is structured as follows:
I have a panel with 150 countries (that I have then grouped in blocs), years 1960 to 2008.
Amongst my variables I have the life expectancy at birth for each country (lifexp) and each year and I would like to compute a weighted mean of life expectancy for the overall sample for each year using the population (pop) as a weight (knowing that I can repeat this procedure for each bloc).
Saying that:
Lifeexpit is the life expectancy of the country i in the year t
and
Popit is the population of the country i in the year t
I would like to compute
- population weights for each year and each country
Ex population weight for country i in year t = (popit *1)/∑popt
*and*
- the weighted mean of life expectancy for the overall sample for each year using the population (pop) as a weight.
Weighted mean of lifeexpt = (∑ lifeexpit*popit)/∑popt
Here attached you’ll find a simplified version of my workfile.
Thanks a lot for your attention and support.
Valentina
My workfile is structured as follows:
I have a panel with 150 countries (that I have then grouped in blocs), years 1960 to 2008.
Amongst my variables I have the life expectancy at birth for each country (lifexp) and each year and I would like to compute a weighted mean of life expectancy for the overall sample for each year using the population (pop) as a weight (knowing that I can repeat this procedure for each bloc).
Saying that:
Lifeexpit is the life expectancy of the country i in the year t
and
Popit is the population of the country i in the year t
I would like to compute
- population weights for each year and each country
Ex population weight for country i in year t = (popit *1)/∑popt
*and*
- the weighted mean of life expectancy for the overall sample for each year using the population (pop) as a weight.
Weighted mean of lifeexpt = (∑ lifeexpit*popit)/∑popt
Here attached you’ll find a simplified version of my workfile.
Thanks a lot for your attention and support.
Valentina
- Attachments
-
- paneleviews.wf1
- (683.66 KiB) Downloaded 381 times
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: weighted mean- country panel data
That helps some, I'm still not sure I understand what you want to compute. But we should be able to figure this out...Let's take the first part.
Now you say that you want to compute population weights for each observation.
The numerator in your expression is simply POPIT, but I'm not certain what's in the denominator since you haven't defined POPT nor indicated over what you wish to sum. Do you want to weight by (1) the sum over all of the population weights or (2) the sum over population weights within cross-sections or (3) the sum of population weights within periods? That is,
(1) sum_{it} pop_it
(2) sum_{i} pop_it for i=1,...N
(3) sum_{t} pop_it for t=1,...T
The first part indicates that LIFEEXPIT and POPIT are observation specific variables with information on life-expectancy and population.Lifeexpit is the life expectancy of the country i in the year t
and
Popit is the population of the country i in the year t
I would like to compute
- population weights for each year and each country
Ex population weight for country i in year t = (popit *1)/∑popt
Now you say that you want to compute population weights for each observation.
The numerator in your expression is simply POPIT, but I'm not certain what's in the denominator since you haven't defined POPT nor indicated over what you wish to sum. Do you want to weight by (1) the sum over all of the population weights or (2) the sum over population weights within cross-sections or (3) the sum of population weights within periods? That is,
(1) sum_{it} pop_it
(2) sum_{i} pop_it for i=1,...N
(3) sum_{t} pop_it for t=1,...T
Re: weighted mean- country panel data
If I correctly understand your question the denominator should be
(3) sum_{t} pop_it for t=1,...T
the sum of population for every period t
(3) sum_{t} pop_it for t=1,...T
the sum of population for every period t
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: weighted mean- country panel data
Then I *think* you want
The @sumsby(pop, country) computes by-country sums of the population variable. We scale the population variable by the by-country sums for form the weights, then compute the weighted mean by summing the product of the weights and the data then dividing by the sum of the weights. Note that your second expression above is ambiguous about the indices in the summations so I'm still not entirely certain what you want to compute. The first weighted mean I provide uses pop as the weights, the second uses the fractional pop as weights.
Code: Select all
series w = pop/@sumsby(pop, country)
scalar wmean1 = @sum(lifeex*pop)/@sum(pop)
scalar wmean2 = @sum(lifeex*w)/@sum(w)
- the weighted mean of life expectancy for the overall sample for each year using the population (pop) as a weight.
Weighted mean of lifeexpt = (∑ lifeexpit*popit)/∑popt
Re: weighted mean- country panel data
Thank you very much Glenn, and sorry if my explanations are ambiguous.
The first expression works.
The second one is not working; I have an error message saying “sizes do not match in matrix function”.
I’m actually computing the weighted mean of life expectancy for each year using pop as the weights with the following expression:
series wmean=(@sumsby(lifeexp*pop, year))/(@sumsby(pop, year))
The first expression works.
The second one is not working; I have an error message saying “sizes do not match in matrix function”.
I’m actually computing the weighted mean of life expectancy for each year using pop as the weights with the following expression:
series wmean=(@sumsby(lifeexp*pop, year))/(@sumsby(pop, year))
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: weighted mean- country panel data
Sorry, you'll have to create the two weighted series first (the scalars don't allow expressions)
The series form you provide should work with no problem.
Code: Select all
series lifepop = lifeexp*pop
scalar wmean1 = @sum(lifepop)/@sum(pop)Who is online
Users browsing this forum: No registered users and 2 guests
