EXAMPLES OF RATS AND TSP

[ Home | Description] | Comparison | User Guide]

Basic Sample RATS Programs

  1. Defining Sample Statement
  2. Reading Data Set
  3. Transforming Data Set
  4. Basic Program
  5. Advanced Program

Basic Sample TSP Programs

  1. Defining Sample Statement
  2. Reading Data Set
  3. Transforming Data Set
  4. Basic Program
  5. Advanced Program

Copyright @1997 Irene Chan
Last Modified: January 27, 1997
If you have any comments, please feel free to email me chani@qed.econ.queensu.ca

[ Home | Description | Comparison | User Guide]

Defining Sample Statements


  1. Reading annual data set starting from 1922 to 1941. CALENDAR 1922 ALLOCATE 1941:1

  2. Monthly data, from February, 1965 through December, 1995: CALENDAR 1965 2 12 ALLOCATE 1995:12
    In the Calendar statement, 2 means February (starting month/period), 12 means periods per year. It will be 4 for Quarterly data.

  3. Daily data (Mondays through Fridays only), from January 2nd, 1995 through December 29th, 1995: CALENDAR(DAILY) 1995 1 2 ALLOCATE 1995:12:29

  4. As above, but seven days per week: CALENDAR(SEVENDAY) 1995 1 2 ALLOCATE 1995:12:29

  5. Data with 24 periods per year, starting in 1950: CALENDAR 1950 1 24 ALL 1995:24

Reading Data Set


  1. The FOODDATA.RAT is a sample RATS time series format data file in which each column is the series's whole data set. FORMAT=RATS denotes the data file is RATS format and org=obs denotes the data format is time series, i.e.data are organized horizontally by obserations. For cross-sectional data fromat, use org=vars, i.e. data are organized horizontally by variables. UNIX users can find this sample data file in /usr/local/rats410/examples CALENDAR 1922 ALLOCATE 1941:1 OPEN DATA C:\RATS\FOODDATA.RAT DATA(FORMAT=RATS,ORG=OBS) / FOODCONS PRRETAIL DISPINC It is very important to have space between the / and each series as RATS is very sensitive to spaces. There is no space between DATA command and its options listed in the parenthesis.

  2. Read an ascii time series data format file without labels at the top of each series in each column . OPEN DATA FOODDATA.DAT DATA(FORMAT=FREE,ORG=OBS) / FOODCONS PRRETAIL DISPINC
  3. use $ for the continuation of the commands to the next line DATA(FORMAT=FREE,ORG=OBS) / FOODCONS $ PRRETAIL DISPINC

Transforming Data Set


  1. To create a linear time trend series: SET TREND = T
  2. To create a MA(2) average series, {1} indicates a one period lag, use the negative number for a one period lead, {-1} : SET AVGPRICES = (PRFARM+PRFARM{1})/2.0
  3. Taking First-difference of Y: Two different ways of taking the first-difference of Y: SET DY = Y - Y{1} DIFF Y / DY
  4. Two ways of taking the natural log of X: SET LX = LOG(X) LOG X / LX
  5. Basic Functions: set x = y**2 /* Square of Y */ /* inverse and transpose of Y iff x and y are the same type of matrix, e.g. rectangular, symmetric, etc. */ comp x = inv(y*tr(y)) set x = sqrt(y) /* Square root of Y */

Basic Program


* the monthly data starts from 1971:1 to 1995:12 cal 1971 1 12 all 1995:12 * beg is a integer contains the starting date of my regression comp beg = 1972:1 ;* comp is the abbrev. of compute comp enda = 1994:1 ;* enda is the end date * use display (or its abbrev., disp) to display the string or * integers / real numbers display 'first' * if you don't trust me, use %datelabel to see what beg is display %datelabel(beg) * Defining the range of my regression's sample period smpl beg enda set trend = t * print the series, need to have spaces in between / print / trend * open the data file OPEN DATA FOODDATA.DAT DATA(FORMAT=FREE,ORG=OBS) / FOODCONS PRRETAIL DISPINC /* Now, we want to source the sample procedure from RATS, Dickey-Fuller unit root test */ * noecho disables the option of diplaying the whole procedure file to * the terminal SOURCE(noecho) C:\RATS\DFUNIT.SRC ;* DOS source(noecho) /usr/local/rats410/examples/dfunit.src ;* unix * need @ to execute the procedure, can read the documentation inside * the DFUNIT.SRC for other options @DFUNIT(TREND,LAGS=2) foodcons * Run OLS, foodcons is the dependent variable * the # is a supplementary card of linreg command which * contains the list of regressiors include a constant (intercept), * prretail[t-1], prretail[t-2] preetail[t-3], dispinc[t], dispinc[t-2] * starting from beg+3 avoids the missing observation, resid is the residuals linreg foodcons beg+4 enda resid # constant prretail{1 to 3} dispinc{0 2} * if you want to graph two series in one page open plot first.gsp ;* for UNIX version open plot first.rgf ; * for DOS RATS386 version graph 2 # FOODCONS # PRRETAIL * create a new RATS data file dedit(new) c:\irene\new.rat ;* for DOS version dedit(new) /home/chani/new.rat ; * for UNIX version store trend ;* this is the only new series created in this RATS session save ;* have to put save in order to have the series in the file end ;* sayonara

Advanced Program


Defining Sample Statements


  1. Reading annual data set starting from 1922 to 1941. FREQ A; SMPL 1922, 1941;

  2. Monthly data, from February, 1965 through December, 1995: FREQ M; SMPL 1965:2, 1995:12;

  3. Weekly data, from 15th week of 1965 through 52th week of 1995: FREQ W; SMPL 1965:15, 1995:52;

Reading Data Set


  1. The DATA.TXT is an ascii file which contains data organized horizontally by observation (the usual Time Series data format). DATA.TLB is an TSP's own binary data format file. FREQ A; SMPL 61,75; ? or you can write smpl 1961 1975; READ(FILE='DATA.TXT',BYOBS) GNP CONS I;
  2. There is an alternative way to read the data if you don't like to have data stored in a separate file: DATA.TSP

  3. You can store the series in TSP's data base. FREQ A; SMPL 61,75; READ(FILE='DATA.TXT',BYOBS) GNP CONS I; genr logc = log(cons); out cons; ? a new TSP data file is being created and names as "cons.tlb" keep logc; ? I only want to store the new series in this data base

  4. To read this TSP data fille FREQ A; SMPL 61,75; in cons; ? loading the data base into this tsp session print cons;

Transforming Data Set


  1. To create a linear time trend series: TREND AA; ? AA is the trend series
  2. To create a MA(2) average series, (-1) indicates a one period lag, use the positive number for a one period lead, (+1) : GENR AVGPRICES = (PRFARM+PRFARM(-1))/2.0 ;
  3. Taking First-difference of Y: GENR DY = Y - Y(-1);
  4. Taking the natural log of X: GENR LX = LOG(X);
  5. Basic Functions: genr x = y**2; ? Square of Y mat x = y'; ? transpose of y matrix mat x = y"; ? inverse of y matrix genr x = y**(1/2) ; ? Square root of Y time series

Basic Program


FREQ A; SMPL 61,75; READ(FILE='DATA.TXT',BYOBS) GNP CONS I; ? The following loop is the major advantage in TSP over other software ? It can loop over the variables and rename the variables with l_ ? This dot loop is extremely useful if you have repetitive loops for ? G-7 countries say. dot gnp cons i; genr l_. = log(.); enddot; ? The above loops generates l_gnp for log(gnp), l_cons for log(cons) etc. ? Regopt controls the calculation and output of the regression diagnostics for OLSQ ? PVPRINT, PVCALC means the p-values will be printed and stored ? TSP won't print the p-values unless with this option is turned on ? Stars indicates the significance of diagnostics test statistics (default is 5% level of significance) ? LMLAGS = 1, since this is annual data, I just want to test the ? the lags =1 for autocorrelation errors REGOPT(PVPRINT,STARS,LMLAGS=1,pvcalc) all; ? Turn on all diagnostics. OLSQ l_cons C l_gnp; ? Regress CONS on GNP and a constant. stop; ? the following is the output from the above regression TSP Version 4.3A (09/24/96) RS/6000 3.2 136MB Copyright (C) 1996 TSP International ALL RIGHTS RESERVED 01/28/97 12:53PM In case of questions or problems, see your local TSP consultant or send a description of the problem and the associated TSP output to: TSP International P.O. Box 61015, Station A Palo Alto, CA 94306 USA PROGRAM LINE ****************************************************************** | 1 INPUT '/u/chani/login.tsp'; | 1 options memory = 200 ; | 2 FREQ A; | 3 SMPL 61,75; | 4 READ(FILE='DATA.TXT',BYOBS) GNP CONS I; | 5 ?genr logc = log(cons); | 5 ?print logc; | 5 | 5 dot gnp cons i; | 6 genr l_. = log(.); | 7 enddot; | 8 ?print l_cons logc; | 8 | 8 | 8 REGOPT(PVPRINT,STARS,LMLAGS=1,pvcalc) all; ? Turn on some diagnostics. | 9 OLSQ l_cons C l_gnp; ? Regress CONS on GNP and a constant. | 10 EXECUTION ******************************************************************************* Current sample: 1961 to 1975 Equation 1 ============ Method of estimation = Ordinary Least Squares Dependent variable: L_CONS Current sample: 1961 to 1975 Number of observations: 15 Mean of dependent variable = 6.42660 Std. dev. of dependent var. = .172101 Sum of squared residuals = .427572E-02 Variance of residuals = .328902E-03 Std. error of regression = .018136 R-squared = .989689 Adjusted R-squared = .988896 Durbin-Watson statistic = .580437 ** [.005] Breusch/Godfrey LM: AR/MA1 = 10.9036 ** [.001] Wald nonlin. AR1 vs. lags = .645037 [.422] ARCH test = .178478 [.673] CuSum test = 1.24080 ** [.004] CuSumSq test = .465654 * [.020] Chow test = 6.81222 * [.012] LR het. test (w/ Chow) = 22.9196 ** [.000] White het. test = .256910 [.879] Jarque-Bera normality test = .393620 [.821] F-statistic (zero slopes) = 1247.76 ** [.000] Akaike Information Crit. = -5.05831 Schwarz Bayes. Info. Crit. = -7.80178 Log of likelihood function = 39.9373 Estimated Standard Variable Coefficient Error t-statistic P-value C -1.10910 .213385 -5.19766 ** [.000] L_GNP 1.08967 .030848 35.3236 ** [.000] Variance Covariance of estimated coefficients C L_GNP C 0.045533 L_GNP -0.0065809 0.00095161 Correlation matrix of estimated coefficients C L_GNP C 1.00000 L_GNP -0.99976 1.00000 ID ACTUAL(*) FITTED(+) RESIDUAL(0) 0 1961 6.1360 6.1122 +* 0.02375 + | + 0 1962 6.1798 6.1737 +* 0.006140 + |0+ 1963 6.2174 6.2159 + 0.001474 + 0 + 1964 6.2704 6.2718 + -0.001376 + 0| + 1965 6.3245 6.3342 + -0.009618 +0 | + 1966 6.3735 6.3971 *+ -0.02366 0 + | + 1967 6.4022 6.4264 *+ -0.02416 0 + | + 1968 6.4511 6.4731 *+ -0.02198 0+ | + 1969 6.4852 6.5007 *+ -0.01545 0 | + 1970 6.5056 6.4972 +* 0.008477 + |0+ 1971 6.5394 6.5293 + 0.01013 + |0+ 1972 6.5971 6.5902 + 0.006991 + |0+ 1973 6.6416 6.6466 + -0.005059 + 0| + 1974 6.6331 6.6264 + 0.006664 + |0+ 1975 6.6420 6.6043 + * 0.03767 + | + 0 CUSUM PLOT ***** **** CUSUM PLOTTED WITH C UPPER BOUND (5%) PLOTTED WITH U LOWER BOUND (5%) PLOTTED WITH L MINIMUM MAXIMUM -10.25310 13.42128 |-+---------------------0---------------------------+-| 1963 | L C U | 1964 | L |C U | 1965 | L | C U | 1966 | L |C U | 1967 | L | C U | 1968 | L | C U | 1969 | L | C U | 1970 | L | C U | 1971 | L | C U | 1972 | L | 2 | CU 1973 | L | 2 | CU 1974 | L | UC | 1975 | L | U C | |-+---------------------0---------------------------+-| -10.25310 13.42128 MINIMUM MAXIMUM CUSUMSQ PLOT ******* **** CUSUMSQ PLOTTED WITH C MEAN PLOTTED WITH M UPPER BOUND (5%) PLOTTED WITH U LOWER BOUND (5%) PLOTTED WITH L MINIMUM MAXIMUM 0.00000 1.00000 |-+-------------------------------------------------+-| 1963 | 2 M U | CL 1964 | LC M U | 1965 | LC M U | 1966 | LC M U | 1967 | LC M U | 1968 | 2 M U | CL 1969 | C L M U | 1970 | L C M U | 1971 | L C M U | 1972 | L C M U | 1973 | L C M U | 1974 | L C M U | 1975 | L 3 | CMU |-+-------------------------------------------------+-| 0.00000 1.00000 MINIMUM MAXIMUM ******************************************************************************* END OF OUTPUT. MEMORY USAGE: ITEM: DATA ARRAY TOTAL MEMORY UNITS: (4-BYTE WORDS) (MEGABYTES) MEMORY REQUESTED : 50000000 200.0 MEMORY ALLOCATED : 33500000 136.0 MEMORY ACTUALLY REQUIRED : 986 2.1 CURRENT VARIABLE STORAGE : 762