On Fri, 4 Jul 2008, Allin Cottrell wrote:
On Fri, 4 Jul 2008, Davoud Taghawi-Nejad wrote:
> I have a dataset, which I would like to compact form 10 to 1. In other
> words, there are 10 measurements a year. But I would like to average the
> 10 obs int 1. I try the following:?
>
> ? setobs 10 1:01
> Full data range: 1:01 - 50:10 (n = 500)
>
> ? dataset compact 1
> This command won't work with the current periodicity.
That's right: frequency 10 is not supported for compaction. You
can, however, compact data of arbitrary frequency using matrix
methods. The following script creates a frequency-10 dataset,
adds a random variable, and converts to frequency 1 by averaging:
nulldata 50
setobs 10 1.1 --special
genr x = normal()
matrix X = x
matrix Z = meanc(mshape(X,10,5))'
Z
nulldata 5 --preserve
setobs 1 1970 --time-series
series compx = Z
print compx --byobs
Alternatively, you could coerce your dataset into a panel structure and
use the special panel functions; this will also take care of possible
missing values. Example:
<script>
nulldata 50
genr x = normal()
setobs 10 1:1 --stacked-time-series
genr mx = pmean(x)
genr time
smpl time=1 --restrict
delete x time
</script>
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti