TSP Tutorial, Part 2

This document assumes you have TSP up and running. We will discuss more thoroughly the difference between interactive and batch programming, one how to enter data, and some details associated with your first TSP problem set.

Note on TSP help: The help menu on GiveWin provides help about GiveWin, and not about TSP commands. For help on using TSP commands, scroll down the modules window and click on ‘start TSP help’.

Interactive versus Batch:

Batch processing allows you to take a complete TSP program you have written and run it as a unit. First, you will need to write a TSP program and save it with a .tsp extension. To do this, start up TSP-through-the-looking-glass and click on the File-New TSP Workspace. Write the program in the window provided, and save it with the .tsp extension. (You can also write the program in a text editor like “Wordpad”.) Once you have the program written and saved, start up GiveWin, and click on file-open. Select the .tsp program you wish to run. (Be sure to select the file type so that .tsp programs are made visible in the open-file window.) The program will open in a GiveWin window. To run in, click on “modules-run TSP”, and let ‘er rip. The program run and output will appear in a window in the GiveWin interface with a .out extension. The output will repeat all lines of your program, the results and mention the amount of memory used; errors will also appear if your program bombs. (If it does, go back and change things in your program and repeat these steps .) You will need to actively save this output, so go to File-Save and save it somewhere. If you do your assignments in batch, you can print out the contents of this .out file and hand it in.

In batch programs, the lines of code end in semicolons, and there are some commands that only work in batch, such as “dot”. “dot” is a special type of looping command. If you try to use the “dot” command interactively, you will get an error. Batch programs should be self-contained. That is, you should set any desired options, establish the sample size and frequency, read in the data, and write the output all within the program.

(Refer to the manuals for ways to redirect output to files other then the default.)

Interactive mode, rather than batch, is better if you are just getting started with TSP, or if you wish to examine your data as you go –perhaps to confirm that you are indeed doing what you want to be doing. Interactive is run directly from the TSP prompt that you get when you start a TSP session. The prompt is a line number with a question mark (?). In interactive mode, output is printed directly to the screen, as the default. GiveWin allows you to print the entire interactive window, so, if you do your assignment in interactive mode, make sure you hand in a printout of the window showing your commands and the resultant output.

Interactive mode does allow you to redirect the output of your commands to a file. So if you wish, you can work interactively, but only write the output you want. (See OUTPUT command under TSP help.) Note: if you choose to do lots of exploratory stuff before tackling the assignment questions, great, but please don’t hand in reams of paper. We are really only interested in you answers to the assignment questions.

Reading in Data:

To get the data, click on the website link and save what comes up to a file somewhere on your hard drive.

Apparently there are many ways to read in data from TSP. The best is the command READ, which allows you to read in directly from excel or other formats. When you read in, be sure to give the full and correct pathname and filename where you put the dataset you downloaded.

It is always a good idea to check if you did things correctly, at least until you are familiar with what you are doing. Here is both a batch and an interactive example of how you might set up and read in data for part 2 of problem set 2:

Batch:

? In batch, you can include comments by starting a line with a ? question mark. Comments are ignored by the program, and note ? how I use them in the program.

? Note also that comments do not end in semicolons

?

? OK here we go

freq m; ? set data to monthly

smpl 89:9 99:8; ? indicate starting/ending periods

read(file=”c:\documents\ec141\ex2data.xls”);

show; ? gives info about data

print ibm; ? prints the column of ibm

? maybe you will want to try plots or other exploratory stuff

? now you would add lines that answer the problem set questions

Interactive: here, question marks are the TSP prompt; click <return> after each line.

1 ? freq m

2 ? smpl 89:9 99:8

3 ? read(file='c:\documents\ec141\ex2data.xls')

4 ? show

Current frequency: MONTHLY

Current sample: 1989:9 to 1999:8

Current internal limits:

500000 allocated words of working space (MEMORY= 4.0)

166666 data points in a regression (T*(K+3))

or observations in a series

20000 variables + program lines /SYMCOM/

30000 arguments in a command or FRML/model /ARGCOM/

or non-numeric names in a DOT loop

20000 words for names > 8 characters /LNGCOM/

( 0 names of 2 words each in use = 0. percent).

500 maximum bytes in a free-format line /CRDCOM/

80 allocated bytes in a free-format line (LIMCOL)

5 ? print ibm

IBM

1989:9 -0.34317

1989:10 0.30301

1989:11 -0.026183

1989:12 -0.035851

1990:1 0.047809

1990:2 0.053229

etc…

Other tips for the problem set:

Random draws: The random number generator draws from a normal distribution by default, and it draws as many times as you have indicated when you set the sample size with the command SMPL. This example draws 10 observations from the specified normal and saves the results to a variable called myrand. Try it and then print myrand. Repeat the random draw command and print myrand again. Do you get the same numbers?

1 ? smpl 1 10

2 ? random (mean=8,stdev=4) myrand

3 ? print myrand

If you wish to get the same numbers for each draw then you must set the “seed” before each draw (the seed can be almost any number):

1 ? smpl 1 10

2 ? random(seedin=687)

3 ? random (mean=8,stdev=4) myrand

4 ? print myrand

5 ? random(seedin=687)

..repeat lines 3 and 4..

CDFs: the command CDF( ) will provide you with upper-tail, lower-tail, one- or two-tail critical values or significance level, depending on your preference. See the manual for more details. The default is the normal distribution. For example, type:

1 ? cdf(inv,uptail) .05

NORMAL Critical Value: 1.644854, Upper tail area: .05000

Using output from a function:

At times, you will want to use the values calculated from a function. For example, suppose you calculated the mean of one stock’s return and want to divide it by the mean of another. You use MSD to get the means, and the @<value> variables are automatically created. Beware that these will be written over each time you run the command, so you will want to create permanent variables, as in this example:

1 ? msd(silent) gmills

2 ? print @mean

@MEAN = 0.011522

3 ? set avgmills = @mean

4 ? print avgmills

AVGMILLS = 0.011522

5 ? msd(silent) gm

6 ? print @mean

@MEAN = 0.010541

7 ? set myratio=avgmills/@mean

8 ? print myratio

MYRATIO = 1.09307

The silent option suppresses output.

Important: The “set” command was necessary to make myratio be a scalar. Otherwise I would have gotten a long column of values 1.09307 equal to the length of the SMPL established when reading in the data.

Refer to the manuals to find what @<value> variables are created for each command.

Dummy Variables:

To create dummy variables (variables that take on a value 0 or 1 according to some criterion) use the example below, where a variable dumvar is created that takes on a value of 1 if what follows the equal sign is true, and zero if it is false. In this case, dumvar=1 if the variable called var1 has a value greater than 5, and 0 otherwise.

1 ? dumvar = (var1>5)

Repeating commands (Batch only):

Sometimes you want to duplicate commands for several variables. To avoid unnecessary repetition and tedium, use the dot command. In this example, the statements loop over the variables x, then y, and then z, creating new variables called newx, newy and newz, which are then each regressed on a constant and a variable called var1. The statements then save the fitted values from the regression into variables called fittedx, fittedy and fittedz. Notice how the dot “.” is used both as a placeholder for the names of the new variables (new. and fitted.), and as a placeholder for the actual variables in the calculations (100*(.)).

1 ? dot x y z ;

2 ? new. = 100*(.) ;

3 ? olsq new. c var1 ;

4 ? copy @fit fitted. ;

5 ? enddot ;

I think you can loop in interactive mode, but not with the capability of looping over variable names and using them as variables within the loop; (Refer to the manuals).