/******************************************************************/ /* */ /* Reading Citibase Data */ /* */ /* Frank Schorfheide */ /* */ /******************************************************************/ /* filename: loaddata.g ** created: 09/18/97 */ /* This program illustrates ** 1) how to read data from an ASCII file ** 2) transform the data ** 3) plot the data ** 4) compute some descriptive statistics */ cls; library pgraph; /* in order to be able to create some decent graphs, we ** have to attach an external library that expands the set ** of available commands, there are many libraries for all ** kinds of applications... you could check the manual */ /* Time series, extracted 05/15/97 ** P16 = POPULATION: TOTAL CIVILIAN NONINSTITUTIONAL (THOUS.,NSA) ** GDPD = GROSS DOMESTIC PRODUCT:IMPLICIT PRICE DEFLATOR (INDEX,92=100)(T7.1) ** GDPQ = GROSS DOMESTIC PRODUCT ** Quarterly Data from 1960:I to 1996:IV ** ** The time series are in the ASCII file data1.prn ** arranged in 3 columns with 148 observations per column */ load data_q[148,3]="c:/uni/yale/teaching/econ550/gauss/data1.prn"; /* First we do some transformations */ series = zeros(148,2); series[.,2] = data_q[.,2]; series[.,1] = 1000*data_q[.,3] ./ data_q[.,1]; series = ln(series); /* series now contains the price deflator and GDP per capita in its columns, ** both in logs... */ /* Compute growth rates: from 1960:II to 1996:IV ** The growth rates are obtained by differencing the log data ** delta(t) = ln y(t) - ln y(t-1) = ln y(t)/y(t-1) approx y(t)/y(t-1) - 1 */ series = series[2:140,.] - series[1:139,.]; ti = seqa(1960.25,0.25,139); /* Let's do some descriptive statistics... ** The easiest are the mean and the standard deviation: ** there are procedures we can use directly... ** the procedures compute the statistics for each column ** individually and collect the results in a vector */ means = meanc(series); stds = stdc(series); "The mean is :" means'; "The standard deviation is:" stds'; /* Now let's compute the sample variance directly, sumc adds all the ** numbers in the columns of a matrix */ /* First we determine the number of observations */ nobs = rows(series); /* Now we compute the variance, the formula might appear a bit messy ** note the "Kronecker product" .*., every element of the vector ** ones(nobs,1) is multiplied by the 1*2 vector means' <- note the transpose! ** which creates a nobs*2 matrix that is of the same dimension as series. */ vars = (1/(nobs-1))*sumc( (series - ones(nobs,1).*.means')^2 ); /* We can now take the sqrt and compare it to the output of stdc */ "The sample variance is :" vars'; "The standard deviation is:" sqrt(vars'); /* You can direct the screen output into an ASCII file */ output file = descstat.out reset; outwidth 256; "The mean is :" means'; "The standard deviation is:" stds'; "The sample variance is :" vars'; outwidth 80; output off; /* Creating decent graphs in GAUSS is a PAIN!!!!! ** you have to redefine all kinds of global variables to set ** line thickness, height of axis, ... ** this gives you some idea how to do it ** just play around with the values and see what happens... */ graphset; begwind; margin(1,1.2,1,1.2); /* This command is quite useful: ** you can divide the screen into different segments and ** create more than one plot per window. Here we are just using ** a single window, try changing the first two numbers and see what ** happens */ window(1,1,0); fonts("microb"); _ptitlht= 0.3; _paxht = 0.25; _pnumht = 0.2; _protate= 0; _pcolor = 2; _plctrl = -1; _pltype = {6 2}; _plwidth= 1.8; /* Name the AXIS labels */ ylabel("Growth (%)"); xlabel("Period"); /* Create a Legend */ _plegstr = "Output\000Prices"; _plegctl = {1 4 1962 -2.5}; xy(ti,100*series); endwind; /* Exercise: try to compute the median using the following steps: ** 1) Define two variables series1, and series2, consisting of only ** the first or second column of series, thus representing only one variable. ** 2) use the command sortc to sort series1 and series2 (seperatly), define ** the sorted vector as series1s and series2s ** ** Purpose: Sorts a matrix of numeric data. ** Format: y = sortc(x,c); ** Input: x NxK matrix. ** c scalar specifying one column of x to sort on. ** Output: y NxK matrix equal to x and sorted on the column c. ** sortc sorts the rows of a matrix with respect to a specified column. That is, ** it sorts the elements of a column and arranges the rows of the matrix in the ** same order as the sorted column. ** 3) It turns out that the number of elements nobs is odd. ** At which position in the vectors series1s and series2s is the median? ** 4) Print the median for each series */