[Gretl-users] Correcting for inflation

Allin Cottrell cottrell at wfu.edu
Sat Apr 11 11:52:17 EDT 2009


On Sat, 11 Apr 2009, Raz Lev wrote:

> the problem I have was 'matching' the CPI data to the records -
> I have 400,000 records and was not sure how to match the right
> CPI to each one (or, how to create 400,000 CPI records in the
> same order as the other observations).

400,000 monthly CPI figures would be 33,333 years' worth, so I
assume you can't have that.  Even 400,000 daily observations would
be about 1000 years' worth, so I guess you don't have that either.

My best guess, then, is that you have

(a) a panel with a large number of "individuals" observed in each
of several months or years, plus

(b) a plain time series of CPI figures, covering all the time
periods in the panel sample,

and you want to expand the CPI data into panel form, so that
(e.g.) the CPI value for 1980:01 gets written into each slot in
the big dataset that records an individual's characteristics in
1980:01.

If my interpretation is right, this is a somewhat fiddly task.
Here's one way to do it (I suspect there may be a more elegant
way).  Let's say I have these CPI data in cpi.txt:

date cpi
1980:01 100
1980:02 101
1980:03 103
1980:04 105
1980:05 106

and let's say I want to create a data file containing 30 stacked
copies of this series for 30 panel units.  Then

<script>
open cpi.txt       # contains time-series data
scalar n = 30      # assuming 30 panel units
scalar T = $nobs   # number of CPI observations
scalar nT = n * T  # target number of observations
matrix m = zeros(nT, 1)
scalar k = 1
loop n --quiet
   loop j=1..T --quiet
      m[k] = cpi[j]
      k++
   endloop
endloop

# create full-length dataset, preserving the matrix
nulldata nT --preserve
# convert matrix to series
series bigcpi = m
# define the new dataset as a panel
setobs T 1:1 --stacked-time-series
# check that our expanded series looks OK
print bigcpi --byobs
# save as gretl data file
store bigcpi.gdt bigcpi
</script>

The new data file bigcpi.gdt can now be appended (File/Append
data/Standard format) to an existing panel data file in stacked
time series format.

Allin Cottrell




More information about the Gretl-users mailing list