Brief Introduction To NLOGIT
Brief Introduction To NLOGIT
Brief Introduction To NLOGIT
HINT: Do not ever close this window. You must have a project window open for the other functions of the program to operate.
NLOGIT uses a standard Windows style statistical package, three window mode of operation. The first window you will see is called the project window. A project consists of the data you are analyzing and the results of your computations, such as estimates of coefficients, other matrices you might have computed, and so on. As well see shortly, this window contains an inventory of the things you have computed - that inventory will grow as you manipulate your data. The second main window that you will use is the editing window. This will be the place where you put your instructions to NLOGIT As with any Windows program, NLOGIT makes use of many menus and dialog boxes. However, you will find at some point quite soon that the menus are too slow for what you wish to do, and you will switch to a command format in which you type out your instructions to get the program to do computations such as regressions. Well demonstrate shortly. Open an editing window by clicking File:New to open a 2 item dialog box. The item highlighted is Text/Command document, which is what you want, so just click OK to open the editing window. This will usually be your first step after you start NLOGIT
Your desktop will appear as below after you open your editing window.
This window is the input window. You are now ready to start using NLOGIT to analyze data or do other computations. You will put your instructions in this window. When you (the program) carry out the instructions, the numerical results will appear in the third main window, the output window. The output window is created automatically for you when you issue a command. Well look at an example below. There will be many other transient windows that you will open and close. For example, when you produce a plot or use matrix algebra to produce a result, or when you enter data by reading a spreadsheet, you will use one or another sort of window which you will open, then probably close as you move on to your next computation or operation. The three primary windows, project, input, and output, will usually stay open on the desktop at all times. No doubt you will size them and move them around to arrange the desktop in a way you prefer.
Our first step is put these data in the program in a place where we can use them. There are many ways to do this, including importing from another program, such as Microsoft Excel. Well begin from scratch, and type them in directly. (This will take a few minutes, but it will familiarize you with an important part of NLOGIT.) The button second from the right at the top of your screen (with a grid icon) activates the data editor. When you first activate it, the data editor is empty. You wish to put five new variables in it. Step 1, then, is to press the right mouse button to activate a menu which will create a column for you to put data on a variable into.
New Variable... Import Variables... Export Variables... Sort Variable... Set Sample > Split Window
When you select New Variable, a dialog box will appear. This box allows you to create a column in your spreadsheet for a variable. Weve typed the name YEAR in the name field. Then, press OK - there is no need to enter a formula - though you can if you wish. Press OK after you enter the name of the new variable.
Hint: If you press this button, you will activate the Help feature. This opens the electronic manual.
This is a list of the mathematical functions that are available for transformations of variables.
We repeat this for each of our 5 variables. The data editor will be reformatted as a grid, and we enter the data on our five variables. The end result appears as follows:
4 Use the usual editing keys, , , . , Enter, Backspace, and so on to move around this spreadsheet style data editor. Enter values as you would in any spreadsheet program. When you are done entering data, just close the window by clicking . Or, just minimize it, in case you want to come back later. Hint: This window is updated automatically. All variables that exist are in this window at all times, regardless of how or when they are created.
Before moving on to the analysis, we close the data editor by double clicking the grid icon at the upper left of clicking the box at the upper right of the editor (not the topmost one, which closes the whole program). We now have five variables in our project. Notice that the project window has changed to reflect this: The original project window that came up when we started showed nothing next to the Variables item. Now, by clicking the + box next to Variables, we find the list of our 5 variables.
The raw data are ready to analyze. In order to carry out the computations we are interested in, it is necessary to transform the data to y = Real Investment = (Inv/CPI)/10 (trillions), X = x1 = Constant term equals 1 for each observation, x2 = Trend, x3 = Real GNP = (GNP/CPI)/10 (trillions), x4 = Real Interest Rate = Interest - Inflation, x5 = Inflation Rate = 100%[(CPIt - CPIt-1)/CPIt-1] with CPI0 = 79.06 from a footnote.
5 As in all cases, there are many ways to do these computations. The method you will use most is to put the necessary instructions in your input window, and have them carried out by the program. The steps are shown below. The instructions needed to do these computations were typed in the editing screen. (The screen is activated first by placing the mouse cursor in it and clicking once.) Notice that there are three instructions in our editor. The instructions are: SAMPLE explicitly defines the current sample to have 15 observations; CREATE defines the transformed variables that we want in our X matrix; NAMELIST defines a matrix named X which contains these 5 variables. Each command begins on a new line, and consists of a verb followed by a semicolon, the instructions, and a dollar sign to indicate the end of the command. The steps needed to carry out the commands once they are typed are shown with the figure. Capitalization and spacing do not matter. Type the text in any fashion you like, on as many lines as you wish. But, remember, each command starts on a new line. Step 1: Click Edit: Select All. This will select the commands in the screen. You can also select only some by using your mouse.
Step 2: Click the GO button. This will submit your commands. They are then carried out.
/10
/10
We will compute a vector of regression coefficients by the familiar least squares formula b = (XX)-1Xy. Before we do this, there are a few points we must note. First, every computer package which does this sort of computation has its own way of translating the mathematical symbols into a computerese that it understands. You cannot type the necessary superscript to tell NLOGIT to invert XX (or any other matrix). The symbol for this is <XX>. Continuing, then, here is another way to compute a result. Step 1: Put the mouse cursor in the command bar and click. (See the figure above). Step 2. Type MATRIX ; List ; BLS = <XX> * Xy $ then press the Enter key.
6 Your output window will contain the results. Some things to note: NLOGIT often uses scientific notation when it reports results. The value -.1658960D-01 means -.1658960 times 10-1, or -0.01658960.
Finally, we consider a menu driven way to enter instructions. Matrix algebra, transformations of variables, and calculator computations involve infinite numbers of different things you might do, so they do not lend themselves to using menus. A menu structured variable transformation program would be intolerably slow, and would necessarily restrict you to a small part of the algebra operations available. But, specifying a regression model is much simpler. This need involve nothing more than pointing at the dependent variable and a list of independent variables. NLOGIT allows just this sort of approach in specifying a model. The dialog begins with Model:Linear Models:Regression... A dialog window will appear next: The model dialog window typically has two or three tabs, depending on the model you will be specifying. For the linear regression model, there is a Main page, on which you select the dependent variable and the independent variables. After you do this, you can either submit the simple specification, by clicking Run, or you can add other optional specifications. For the one shown below, the main page specifies the dependent and independent variables for a linear model, while the Options page will allow you to specify an extended model with autocorrelation, or to specify computation of a robust covariance matrix. You can access the manual, with a full description of the model and how to estimate it, by clicking the ? icon at the lower left of this dialog box. This will be true in many other dialog boxes that NLOGIT presents.
7 To specify the dependent variable, click the menu button then select the variable.
To select the independent variables, including the constant, select each variable from the vertical list, then press the << button to move that variable into your list. You can do this in the other direction if you need to correct an error. Hint: Double clicking a name will move it to the other window. Press Run to estimate the model. This presents a new set of results in your output window.
This concludes the demonstration. You can now exit the program with File:Exit.
Previous four editing files. When you select one of these, it is placed in a new editing window Previous four project files. When you select one of these, the session is restarted with this new project End the session and close the program.
Edit
Standard editing functions used in the editing, input window. You can also cut, paste, and copy among editing, output, and various calculator (matrix, scalar) windows. You can also copy and paste from any window to other software, e.g., from the data editor into Excel or output to Word. Include and Reject menu items are only used when the data editor is active. Use to mark observations in or out of current sample Navigate editing window
10
Insert
Insert things into the editing window. Text file places a whole text file in the window. Insert Item into Project is a powerful processor that starts several operations.
Project
Program parameter settings such as data area size and where to put the trace file.. You should not use this. Same as Insert Item into Project. Use Import to read a data file. Use Export to write a data file for some other program. Data Editor activates the data editor for entering new variables or editing existing ones. Sort observations in a column of data into ascending or descending order. You can also carry other variables with the one you sort. Clear all work areas. Retarts the project. Deletes all data! Use with care.
Model
Use the model menu to specify a model in a dialog box instead of a command. The main page specifies the essential parts, usually the dependent and independent variables. Other pages are for options and extensions, such as heteroscedasticity robust covariance matrices, autocorrelation, or fixed effects.
11
Run
Used with the text editing window. Run line and Run Line Multiple times submit a particular line that you have hightlighted to the program for execution, once or more than once. Run file executes a set of commands that are stored in a command file. This is the same as Insert:File, then Select All and GO. New Procedure is an interactive editor for procedures. This is an advanced feature.
Tools
Invokes windows specific for the scientific calculator and for matrix algebra. These are just convenient windows for arranging results of these operations. Review tables is used for setting up results of model commands. Tools:Options is used for program settings, some the same as in Projedt Settings. This should generally not be needed.
Window
These are the standard Windows functions for arranging the desktop or activating a particular window. The list at the bottom is a complete inventory of the windows currently open. The first two are the project and editing window, respectively. Asterisks indicate that the open window has changed since it was last saved. When you exit the program, you will be asked if you would like to save any window which is open and has been changed since the last save (or since it was opened).
Help
Help contains the full manual for LIMDEP as well as several other summaries and descriptions. The Commands book contains details on each program instruction. The Topics book includes descriptions of specific operations such as how to read a data set.
12
V. Using NLOGIT
This section will provide the information you need to use NLOGIT to analyze your data and to do the other computations described in Econometric Analysis and other econometrics texts. The descriptions will be extremely brief; only the essential features will be described. There are many features of the program that are available to you that will not be mentioned here. However, your Help file contains the full manual for the program, so you can find the additional descriptions there.
13 editing window or in a command window in some context. There are a few conventions that you will need to know about as you create sets of instructions in your editor: (1) Commands are of the form VERB ; specification ; specification ; ... ; ... $ The verb is a command such as READ or REGRESS. Specifications are specific to the context. The internal delimiter is the semicolon character. All commands end with a dollar sign. Tip: If you submit a command and nothing happens, check to see if you forgot the ending $. (2) The order of the specifications in a command never matters. (3) Case and spacing never matter in any instruction. You can type commands in any way that you prefer. Use spacing and upper and lower case to make your commands easy to read. (4) Every new command which begins with a verb must begin on a new line. (5) Any line that begins with a question mark, regardless of where it appears, is treated as a comment and not used in any function. This allows you to put comments in your command sets. The fifth window shown in the demonstration above shows an editing screen which contains a sequence of three instructions, Sample, Create, and Namelist, that follow these conventions. You can obtain a full list of the verbs used in NLOGIT in the online Help file in the Commands book. Many of the computations that you do will create numeric entities that have names. For example, your data set will consist of n rows, or observations, on a set of variables, which will have names so that you can refer to them later. There are a few reserved names in NLOGIT. These are reserved for use by the program for results that are saved automatically when you estimate a model. You can see the list of these in your project window: Reserved names are always marked with keys (to indicate that they are locked.) The variable X is our own. Notice that it is unmarked. The name ONE is used to indicate the constant term in a model. This is not a valid variable name, either, though it does not appear in the project window. You will be warned if you try to use a reserved name. These three matrices are created by the program and are reserved. You can use matrix algebra to create other matrices with names that you choose. These are scalar values that are created when a regression or other model is estimated. These names are also unavailable for other uses. You can use the calculator to calculate other values that you can give a name to, so that you can use it in some other expressions. Two other names that are used by the program are N, the current sample and PI, the number 3.14... The project window will always contain a full inventory of the named entities that exist in your project. This window is more than just a listing, however. By double clicking any name in the project window, you can invoke some processor that is relevant to the name you selected. For example, if you double click a variable name, you will invoke the data editor. If you select a variable name, then click the right mouse button, a different menu of functions is offered. There are many other functions embedded in the project window that you can start by clicking the different names in the lists. Section 3.5.2 of the manual contains details. Names that you create must all obey the following conventions: (1) They must contain from 1 to 8 characters. No name may contain more than 8 characters. (2) Names must begin with a letter. Numbers and underscores may appear after the initial letter. (3) Names may only use the 26 letters, 10 digits (0 - 9), and the underscore character. Any other character in a name is likely to cause problems elsewhere, though in most cases a bad name will be noticed. (4) Since case never matters, you cannot create different names by using different cases. Bob = BOB.
14
C. Submitting Commands
In order to submit commands, type them onto the text editing screen, drag your mouse across the ones you wish to submit to highlight them, then press the GO button at the top of the screen. Or, to submit the entire screen contents at once, use Edit:Select All, then GO. At the left, we have a screen with a number of commands, but at this point, we are only going to execute the Create command. Later we can go back to submit the others. The advantage of this method is that the commands remain in the editor if you wish to use them again. For example, the Regress command has an error in it. FittedY= is supposed to be Keep=. When we submit it, this command is going to result in an error message, but no results. So, we just go back to the editor, fix the error, and try again.
15 If you need to locate an ASCII file to put its full name in your READ command, you can use Insert:File Path from the main menu to navigate to it. This will type the name in the editor screen for you. NOTE: If your ASCII data file contains exactly one row of names at the top of the file, followed by a simple data set with values separated by spaces and/or commas, then you can read the file with the simple command READ ; File = ...<name of the file> ... $ or just by pointing at it with Project:Import/Variables. This will be the usual case, so this is how you should open a data file. If you would rather not use several pieces of software, or are unfamiliar with other programs that can be used to edit an ASCII data file, here is a convenient trick that we often use to get ASCII data into the program and create the data file at the same time. You can READ data directly off the editor screen. The data used in the demonstration could be read as follows: Step 1 is to type the command shown, the names, and the data on the screen in the text editor. We have neatly arranged the columns, but this is not necessary, so long as values are separated by blanks and/or commas. Step 2, is to READ the data, which we do with Edit:Select All, then GO. This can also be written as a text file just by saving the window. Use File:Save. If you do not have any other convenient text editing program, the text editor in EA/LimDep can be used for that purpose. The editing conventions and keystrokes are all the standard ones used in Windows applications.
16 Trn(m,0)=1,1,...(m times), 2,2,..., 3,3,... and so on. Trn(4,0)=1,1,1,1,2,2,2,2,.. Minor = (Age < 21) is the same as the command above. WrkWoman = (Female=1) * (Income > 0) creates a dummy variable = 1 if both conditions are true. Operators are <, >, <=, >=, =, and # for not equal. There are many other functions and variations available for transforming data. Further details appear in Chapter 5 of the manual. Strata: Dummy variables:
G. Lists of Variables.
Many of the computations you will do with NLOGIT will involve sets of variables, and frequently, you will use the same set of variables more than once. There is a simple tool you can use to make this easier, the Namelist command. The command is Namelist ; name = list of variable names $ Thereafter, the name on the left hand side stands for the list of names on the right. An example appears in in Part C above; Namelist ; X = x1,x2,x3,x4,x5$ is followed by a Regress;...;Rhs=X$. This specifies a regression of a dependent variable on the five variables in X. You will see many applications that use this tool. You can have up to ten namelists defined at any time. They may share names. Thus, for example, Namelist;XYZ=X,y,z$ is a valid definition of a namelist that stands for seven names, the five in X plus y and z.
H. Summary
You now have all of the basic tools needed to operate NLOGIT. There are four features remaining to describe, estimating models, using matrix algebra, using the scientific calculator, and writing procedures. Before turning to these, we provide a small application which uses the features described above. We will use a data file called Labor.Dat to fit a log-linear hours equation. These data are a set of 250 observations on womens labor supply, which are provided in Berndt (1992). Just for illustration, we will carry out a Chow test of the hypothesis that the labor supply behavior of women with children in this sample is the same as that of women without children. The sample is divided into two groups of women, one group that did not participate in the labor market and one that did. To carry out our test, we will restrict our attention to those in the latter group. The regression equation we will use is log(hours) = 1 + 2log(wage) + 3Age + 4Educ + . The editor screen is shown below. We would execute all the commands on the screen at once, and collect the results we need at the end.
17
18
The descriptive statistics instructions shown above are also model commands, but they generally have no Lhs variable. Also, some of the model commands will vary a bit for the different information that they require. There are two ways to submit a data description or estimation instruction, directly with program commands or by using the command builder to build your model instruction in a dialog box.
19 A.1. Model Commands In order to submit a model command directly, type it on the screen in your text editing window, highlight it with your mouse, then press GO. Two model commands are shown in the example in the figure in Section VII.C. above. The model commands for the procedures listed above are as follows: Descriptive statistics, means, standard deviations, minima, maxima, sample size: DSTAT ; Rhs = the variables $ Add ;all for skewness and kurtosis. Add ;AR1 for first order autocorrelation. Histograms for discrete or continuous variables HISTOGRAM ;Rhs = the variable $ Add ;Limits = a1,a2,... to specify the interior limits of bins for a continuous variable. Scatter diagrams PLOT ; Lhs = variable on horizontal axis ; Rhs = variable on vertical axis $ Add ;Fill to connect the dots. Add ;Limits = lower,upper to specify a particular range of values for the vertical axis. Add ;Endpoints=lower,upper to spedify a particular range of values for the horizontal axis. Add ;Regression to include a plot of the linear regression line in the figure. Add ;Grid to add a background grid to the figure. For time series data identified with DATES command, ;Lhs=variable may be omitted. The horizontal axis will be labeled with dates, instead. Box-Jenkins identification IDENTIFY ; Rhs = the variable ; Pds = the number of lags $ (;Pds must be given) Cross tabulations for two discrete variables CROSSTAB ; Rhs = first variable ; Lhs = second variable $
Important note: To include a constant term in any of the models listed below, be sure to include a varible named ONE on the Rhs. This is not done automatically in any model specification.
Classical linear regression model REGRESS ; Lhs = dependent variable ; Rhs = independent variables $ Add ;AR1 for Prais/Winsten AR(1) model Add ;Het for Whites robust estimator and the Breusch-Pagan test Add ;Pds = q for Newey-West estimator. Give a value for q (number of lags) Add ;Keep = a variable name to compute a set of fitted values Add ;Res = a variable name to compute a set of residuals Add ;Cusum to carry out cusum test of stability Add ;Plot to plot the residuals To fit fixed and random effects models, make sure that your data arranged so that the first T observations are group 1, the next T are group 2, and so on. Then, to request the model: Add ;Panel ; Pds = T (Note. Do not forget ;Panel for REM and FEM.) You must give the specific value for T. With panel data you can also Add ;RCM to fit a random coefficients model Harveys multiplicative heteroscedasticity model HREG ; Lhs = dependent variable ; Rhs = variables in X ; Rh2 = variables in Z $
20 Instrumental variables estimation 2SLS ; Lhs = dependent variable ; Rhs = variables on the right hand side ; Inst = the list of instrumental variables $. (Include ONE in this list as well.) Add other options the same as REGRESS. Add ;AR1 ; Hatanaka to fit Hatanakas model for autocorrelation. Covariance structure models, as in Section 15.2 of the text TSCS ; Lhs = dependent variable ; Rhs = independent variables ; Pds = number of periods observed $ Data are stacked in groups. Up to 10. Add ; PCSE for Beck, et. als robust covariance matrix for OLS. For this model, there are 3 basic forms: S0=simple linear model, S1=groupwise heteroscedastic, S2=full model with cross group correlation. All 3 are fit. Add ; Model = S0 or S1 or S2 to fit a particular formulation only. Autocorrelation models are R0=none, R1=same for all groups, R2=group specific i. Add ; AR1 to fit all 9 combinations Add ; Model = Si,Rj (i=0,1,2, j=0,1,2) to request a specific formulation. Linear regression with ARIMA disturbances ARMAX ; Lhs = dependent variable ; Rhs = independent variables ; Model = P, D, Q $ (you provide P, D, Q) P = number of autoregressive terms in disturbance model D = number of periods to first difference Q = number of moving average terms. Note: If Q = 0, the model is linear, and you should use REGRESS to estimate it. Seemingly unrelated regressions (up to 5 equations) SURE ; Lhs = list of dependent variables ; EQ1 = list of Rhs variables in equation 1 ; ... ; EQm = list of Rhs variables in last equation $ (Order is the same as Lhs.) Three stage least squares (up to 5 equations) 3SLS (same as SURE, but add ;Inst = the full list of exogenous variables, including ONE $ Discrete and censored dependent variables. All have the same format. PROBIT LOGIT TOBIT ; Lhs = dependent variable ; Rhs = independent variables $ POISSON Nonlinear least squares NLSQ
; Lhs = the dependent variable ; Fcn = definition of the regression function ; Labels = the names used in Fcn for the model parameters ; Start = a set of starting values $
Example: NLSQ ; Lhs = Q ; Fcn = gamma*(delta*K^(-rho) + (1-delta)*L^(-rho) )^(-theta/rho) ; Labels = gamma,delta,rho,theta ; Start = 1,.5,.01,1 $
21 A.2. Using the Command Builder As an alternative to constructing the model commands for model estimation, you can use the interactive command builder. This is a dialog box that writes model commands for you. It begins with the Model item in the main menu at the top of your screen. The submenu offers a set of model groups, then, within each, the specific model specification. Well illustrate it with a regression model with autocorrelated disturbances, using the gasoline data. After we select Models:Linear Models...:Regression, the dialog box presented is shown below. On the Main page, we have selected the dependent variable (LOG_G) and the independent variables (ONE, LOG_PG, LOG_Y, LOG_PPT). The variable LOG_PNC is to be added to the list as well. The variable name is selected in the right hand side window. Then, the << button is pressed to move the name into the set of variables in the model. If you change your mind, you can move variables back into the menu, out of the list by hightlighting in the left hand side box and pressing the >> button, instead. The Options page presents the extensions of the model, such as autocorrelation, panel data, and so on. Autocorrelation is specified by pressing the button in the options page. This opens the dialog box shown at the right, where the estimator is selected.
The autocorrelation dialog is concluded by pressing the OK button. Then, the model request can be submitted by pressing the Run button in the Regress window. The results will appear in the output, along with a copy of the command that is generated. If you wish to resubmit the model request with a small change, you can use Edit:Copy with Edit:Paste to put a copy of the command in your editing window, where you can edit it. (That is how we copied the command below, to our word processor.) REGRESS;Lhs=LOG_G;Rhs=ONE,LOG_PG,LOG_Y,LOG_PPT,LOG_PNC;Ar1$ Note, finally, the question mark at the lower left of the dialog box. This invokes the Help file, and opens it to the chapter on the linear regression model.
22
23 The MATRIX command works the same as CALC, either in the editor screen or in its own Tools window. The MATRIX feature in NLOGIT is extremely large, and includes far too many features and extensions to list here. There are only a few things you need to get started using NLOGITs matrix algebra program. The first is how to define a data matrix, such as X in the example above. The columns of a data matrix are variables, so, as you can see in the example, the NAMELIST command defines the columns of a data matrix. A single variable defines a data matrix with one column (i.e., a data vector) note the use of the variable g in the example. The rows of a data matrix are the observations in the current sample, whatever that happens to be at the time. That means that all data matrices change when you change the sample. For example, NAMELIST;X=ONE,GNP,CPI,MONEY$ followed by SAMPLE;1-20$ defines a 20 4 data matrix, but if you then give the command SAMPLE;11-20$, then X now has only 10 rows. Second, data matrices can share columns. For example, with the X just defined, we might also have a NAMELIST;Z=ONE,GNP,INFL,INTEREST$ Thus, X and Z share two columns. In matrix algebra, the number 1 will represent a column of ones. Thus, if x is a variable, you could compute its mean with MATRIX;List;Meanx=1/n*x1$. There are many matrix operators. The major ones you need to know are (1) +, -, * for the usual addition, subtraction, and multiplication - the program will always check conformability, (2) (apostrophe) for transposition, and (3) <.> for inversion. When you compute a moment matrix, such as XX, you need not both transpose and multiply. The command XX means exactly what it looks like. Finally, in order to define a matrix with specific values in it, you use MATRIX;NAME = [ row 1 / row 2 / ... ] $ Within a row, values are separated by commas; rows are separated by slashes, and the whole thing is enclosed in square brackets. An example appears below. In the same way that every model command creates some scalar results, every model command also creates at least two matrices, one named B which is the coefficient vector estimated, and one called VARB which is the estimated covariance matrix. You can use these in your matrix commands just like any other matrix. For another example, here is a way to compute the restricted least squares estimator defined in Chapter 7 of the text, b* = b - (XX)-1R[R(XX)-1R]-1(Rb - q). For a specific example, suppose we regress y on a constant, x1, x2, and x3, then compute the coefficient vector subject to the restrictions that b2 + b3 = 1 and b4 = 0. In a second example, we compute the Wald statistic for testing this restriction, W = (Rb-q)[R s2(XX)-1R]-1(Rb-q). Note that both examples use a shortcut for a quadratic form in an inverse, and the second example uses both B and VARB. NAMELIST ; X = ONE,X1,X2,X3 $ REGRESS ; Lhs = y ; Rhs = X $ MATRIX ; R = [0,1,1,0 / 0,0,0,1] ; q = [1/0] $ MATRIX ; m = R*b - q ; D = R*<XX>*R ; br = b - <XX> * R<D>m $ NAMELIST ; X = one,x1,x2,x3 $ REGRESS ; Lhs = y ; Rhs = X $ MATRIX ; R = [0,1,1,0 / 0,0,0,1] ; q = [1/0] $ MATRIX ; m = R*B - q ; D = R*VARB*R ; W = m <D> m $
In addition to the operators and standard features of matrix algebra, there are numerous functions that you might find useful. These include ROOT(symmetric matrix), CXRT(any matrix) for complex roots (see Chapter 16 of the text for an application), DTRM(matrix) for determinant, SQRT(matrix) for square root, and a few dozen others. Chapter 10 of your online manual contains the full list of matrix functions. Lastly, a special function, STAT(vector,matrix), is provided for you to display statistical results when you use matrix algebra (or any other means) to compute a coefficient vector and an associated asymptotic covariance matrix. To illustrate, well continue the example above. The asymptotic covariance matrix for the restricted least squares estimator is Asy.Var[b*] = s*2{(XX)-1 - (XX)-1 R[R(XX)-1R]-1R(XX)-1} where s*2 = (y Xb*)(y Xb*)/(n-K-J) Here is a general program that could be used for this purpose. To adapt it to a specific problem, youd need to define X and y and supply the particular R and q.
24
? We do all computations using CREATE, CALC, and MATRIX NAMELIST ; X = the set of variables $ CREATE ; y = the dependent variable $ MATRIX ; R = the matrix of constraints (see Chapter 7 of the text) ; q = the vector on the RHS of the constraints $ MATRIX ; bu = <XX> * Xy $ CREATE ; e = y Xbu $ CALC ; K = Col(X) ; s2 = ee/(n-K) ; J = Row(R) $ MATRIX ; Vb = s2 * <XX> ; Stat (bu,Vbu) $ (Unrestricted) MATRIX ; m = R*bu - q ; D = R*<XX>*R ; br = bu - <XX>*R<D>m ; Vbr = <XX> - <XX>*R*<D>*R*<XX> $ CREATE ; er = y Xbr $ CALC ; s2r = erer / (n K J) $ MATRIX ; Vbr = s2r * Vbr ; Stat(br,Vbr) $
C. Restricted Regressions
The program above is useful for seeing how MATRIX can be used to compute the restricted least squares estimator. It is also general enough that you can easily adapt it to any problem. But, for much greater convenience, since restricted linear regressoin is such a common application, the feature can be built into the REGRESS command, instead. To impose restrictions on a linear regresson model, use this syntax: REGRESS ; Lhs = ... ; Rhs = ... ; Cls: the restrictions, separated by commas if there are more than one $ with coefficients labeled b(1), b(2),... in the same order as the RHS variables. For the specific example above, the absolutely simplest way to obtain the restricted least squares estimates would be REGRESS ; Lhs = y ; Rhs = One,X1,X2,X3 ; CLS: b(2)+b(3)=1 , b(4) = 0 $ (This can be done in the command builder dialog box, but it is not appreciably simpler to do it this way.) Restrictions must be specified linearly, without parentheses. Operations are only + and and multiplication is implied. For example, CLS : 2b(1) + 3.14159b(4) b(5) = 2 is a valid (if strange) constraint. Note that constraints must be in the form linear function = value, even if value is zero. D. Using WALD to Apply the Delta Method and Test Hypotheses For a random vector b with estimated asymptotic covariance matrix,V, the estimated asymptotic covariance matrix for the set of functions c(b) is GVG, where G is the matrix of derivatives, c(b)/ b. This full set of computations is automated for you in the WALD command. Generally, you need only supply the vector and covariance matrix and a definition of the function(s), and NLOGIT computes G (by numerical approximation see Chapter 5 in the text) and the covariance matrix for you. For a regression model, it is even easier; you need only supply the functions. The command for WALD is WALD ; Start = b (the values of the coefficients) ; Var = V (the covariance matrix) ; Labels a set of names for the coefficients (like NLSQ defined earlier) ; Fn1 = first function ; ... $ (up to 20 functions). This coefficient vector and covariance matrix may be any that are obtained from any previous operations. For example, in Example 7.14 in the text, we estimated the parameters [,,] in the consumption function Ct = + Yt + Ct-1 + t. We then estimated the long run marginal propensity to consume, /(1-), which is a nonlinear function, and computed an estimate of the asymptotic standard error for this estimate.
25 The text shows the computations, done the hard way. Here is an easier way to compute the long run MPC and estimate the asymptotic standard error: REGRESS WALD ; Lhs = C ; Rhs = One,Y,Clag $ ; Start = B ; Var = VARB ; Labels = alpha,beta,gamma ; Fn1 = beta/(1-gamma) $
This computes the function and also estimates and reports the standard error and an asymptotic t-ratio. In fact, if you are analyzing the coefficients of an immediately preceding regression , there is yet a shorter way. The following is equivalent to the WALD command above: WALD ; Fn1 = B_Y / (1 - B_Clag) $
When you use the syntax B_Variable name, EA/LimDep understands this to have been constructed from a previous regression, and builds up the function and the results using B and VARB from that regression. WALD also tests linear or nonlinear hypotheses. It automatically computes the WALD statistic for the joint hypothesis that the functions are jointly zero. For two examples, in the preceding, to test the hypothesis that the long run MPC equals 1.0, you would use WALD ; Fn1 = B_Y / (1 - B_CLAG) - 1 $ Second, for the Wald test that we did in the matrix algebra section above, we could have used REGRESS WALD ; Lhs = Y ; Rhs = One,x1,x2,x3 $ ; Fn1 = B_X1 + B_X2 - 1 ; Fn2 = B_X3 $
E. Procedures
The last (and most advanced) tool we will examine is the procedure. A procedure is a group of commands that you can collect and give a name to. Then, to execute the commands in the procedure, you simply use an EXECUTE command. To define a procedure, just place the group of commands in your editor window between PROCEDURE=the name$ and ENDPROCEDURE$ commands, then Run the whole group of them. They will not be carried out at that point; they are just stored and left ready for you to use later. For example, the application above that computes a restricted regression and reports the results could be made into a procedure as follows: NAMELIST CREATE MATRIX ; X = the set of variables $ ; y = the dependent variable $ ; R = the matrix of constraints (see Chapter 7 of the text) ; q = the vector on the RHS of the constraints $ PROCEDURE = CLS $ ... the rest of the commands above ENDPROCEDURE $ Now, to compute the estimator, we would define X, y, R, and q, then use the command EXECUTE ; Proc = CLS $
To use a different model, wed just redefine X, y, R, and q, then execute again. Since the commands for this procedure are just sitting on the screen waiting for us to Run them with a couple of mouse clicks, this really has not gained us very much. There are two better reasons for using procedures. First, the EXECUTE command can be made to request more than one run of the procedure, and, second, procedures can be written with adjustable parameter lists, so that you can make them very general, and can change the procedure very easily. Well consider one example of each.
26 The following computes bootstrap standard errors for least squares. (This will introduce a new command, the DRAW command to sample from the current sample.) Bootstrapping is described in Chapter 5 of the text, and applied in Chapter 10, so, well just proceed to the application: NAMELIST ; X = the independent variables $ CREATE ; y = the dependent variable $ MATRIX ; b0 = <XX> * Xy $ CALC ; K0 = Col(X) ; NREP = 100 $ MATRIX ; Vb0 = 0.0[K0,K0] $ CALC ; CurrentN = N $ PROCEDURE = Boot $ DRAW ; N = CurrentN ; Replacement $ MATRIX ; dr = <XX> * Xy b0 ; Vb0 = Vb0 + 1/NRep * dr * dr $ ENDPROC $ EXECUTE ; Proc = Boot ; N = NRep $ MATRIX ; Stat (b0,Vb0)$ For our second and final example, well construct a procedure for doing a Chow test of structural change based on an X matrix, a y variable, and a dummy variable, d, which separates the sample into two subsets of interest. Well write this as a subroutine with adjustable parameters. This is how a such a procedure that might be included as an appendix in an article would appear. Note that this routine does not actually report the results of the three least squares regressions. To add this to the routine, the CALC commands which obtain sums of squares could be replaced with REGRESS ;Lhs = y ; Rhs = X $ then CALC ; ee = sumsqdev $ /* Procedure to carry out a Chow test of structural change. Inputs: X = namelist that contains full set of independent variables y = dependent variable d = dummy variable used to partition the sample Outputs F = sample F statistic for the Chow test */ F95 = 95th percentile from the appropriate F table. PROC = ChowTest(X,y,d) $ CALC ; K = Col(X) ; Nfull = N $ SAMPLE ; All $ CALC ; ee = Ess(X,y) $ INCLUDE ; New ; D = 1 $ CALC ; ee1 = Ess(X,y) $ INCLUDE ; New ; D = 0 $ CALC ; ee0 = Ess(X,y) $ CALC ; List ; F = ((ee-(ee1+ee0))/K) / (ee/(Nfull-2*K) ) ; F95 = Ftb(.95,K, (Nfull-2*K)) $ ENDPROC Now, suppose we wished to carry out the test of whether the labor supply behaviors of men and women are the same . The commands might appear as follows: NAMELIST EXECUTE ; HoursEqn = One,Age,Exper,Kids $ ; Proc = ChowTest(HoursEqn,Hours,Sex) $