Let me clarify
I believe PMEAN computes the average for each cross-section unit,
which is a block of stock prices and returns in my case.
Instead I want to compute the average across all cross section units
for each time period identifier, and also I need to use a weight--
market value of the stock in my case.
Maybe there is a 'unit' manipulation that would turn pmean into a
function that averages over the cross-section for a time period, but
that does not solve the weighting problem.
I tried wmean(ret,mktval_lag) but it does not give what I expected.
The weighted mean in this case is for an observation, not across
observations.
I could make the WLS trick a function but I am not sure how to loop
over all dates (time identifiers) is an un-failable manner --
consistent with the smpl setting -- not just for my simple example,
but in general.
SAS's PROC SUMMARY and PROC MEANS does this, for example, by allowing
a weight statement and a 'by' (group) statement.
1. Re: Panel data time series means with weighting (Sven
Schreiber)
2. Re: Manipulating a database (Allin Cottrell)
3. Re: Manipulating a database (Allin Cottrell)
----------------------------------------------------------------------
Message: 1
Date: Mon, 05 Apr 2010 14:57:22 +0200
From: Sven Schreiber <svetosch(a)gmx.net>
Subject: Re: [Gretl-users] Panel data time series means with weighting
To: Gretl list <gretl-users(a)lists.wfu.edu>
Message-ID: <4BB9DE32.8020702(a)gmx.net>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
first if your script does what you want, why try to "change a winning team"?
Apart from that, for a weighted mean maybe the wmean() function in
combination with clever sample restrictions could do the job for you,
too. But what exactly do you mean with "time series means" -- I would
have thought the per-unit means of pmean() are just that.
cheers,
sven
MICHAEL BOLDIN schrieb:
> I would like to calculate time series means in a panel data set as
> easily as pmean() and wonder if there is a built in function or
> easier way than my script below. I am computing stock market returns
> for a portfolio where px=1 was set to select the included
> cross-sectional identifiers, and note I also need to weight (by market
> value in this case).
>
> smpl --full
> series retp= NA
> ## Loop over dates
> loop foreach dx 38748 38776 38807
> smpl --full
> ## Set sample dates and selected ids
> smpl DATE= $dx --restrict
> smpl px=1 --restrict
> ## Compute weighted average returns as wls intercept coefficient
> wls mktval_lag ret const --quiet
> series retp=$coeff(0)
> endloop
>
> Second and third thing: I imported the data from EXCEL and the dates
> are numbers (1/1/1900=0), hence my loop over 38748 38776 38807 that
> are month end days. Is there a easy way to get all date ids to loop
> over and format as dates.
> _______________________________________________