Useful Stata Commands (for Stata version 12)

Size: px
Start display at page:

Download "Useful Stata Commands (for Stata version 12)"

Transcription

1 Useful Stata Commands (for Stata version 12) Kenneth L. Simons This document is updated continually. For the latest version, open it from the course disk space. This document briefly summarizes Stata commands useful in ECON-4570 Econometrics and ECON Advanced Econometrics. This presumes a basic working knowledge of how to open Stata, use the menus, use the data editor, and use the do-file editor. We will cover these topics in early Stata sessions in class. If you miss the sessions, you might ask a fellow student to show you through basic usage of Stata, and get the recommended text about Stata for the course and use it to practice with Stata. More replete information is available in Lawrence C. Hamilton s Statistics with Stata, Christopher F. Baum s An Introduction to Modern Econometrics Using Stata, and A. Colin Cameron and Pravin K. Trivedi s Microeconometrics using Stata. See: Readers on the Internet: I apologize but I cannot generally answer Stata questions. Useful places to direct Stata questions are: (1) built-in help and manuals (see Stata s Help menu), (2) your friends and colleagues, (3) Stata s technical support staff (you will need your serial number), (4) Statalist ( (but check the Statalist archives before asking a question there). Most commands work the same in Stata versions 11, 10, and 9. Throughout, estimation commands specify robust standard errors (Eicker-Huber-White heteroskedastic-consistent standard errors). This does not imply that robust rather than conventional estimates of Var[b X] should always be used, nor that they are sufficient. Other estimators shown here include Davidson and MacKinnon s improved small-sample robust estimators for OLS, cluster-robust estimators useful when errors may be arbitrarily correlated within groups (one application is across time for an individual), and the Newey-West estimator to allow for time series correlation of errors. Selected GLS estimators are listed as well. Hopefully the constant presence of vce(robust) in estimation commands will make readers sensitive to the need to account for heteroskedasticity and other properties of errors typical in real data and models. 1

2 Contents Preliminaries for RPI Dot.CIO Labs... 5 A. Loading Data... 5 A1. Memory in Stata Version 11 or Earlier... 5 B. Variable Lists, If-Statements, and Options... 6 C. Lowercase and Uppercase Letters... 6 D. Review Window, and Abbreviating Command Names... 6 E. Viewing and Summarizing Data... 6 E1. Just Looking... 6 E2. Mean, Variance, Number of Non-missing Observations, Minimum, Maximum, Etc E3. Tabulations, Histograms, Density Function Estimates... 7 E4. Scatter Plots and Other Plots... 7 E5. Correlations and Covariances... 8 F. Generating and Changing Variables... 8 F1. Generating Variables... 8 F2. Missing Data... 8 F3. True-False Variables... 9 F4. Random Numbers F5. Replacing Values of Variables F6. Getting Rid of Variables F7. If-then-else Formulas F8. Quick Calculations F9. More G. Means: Hypothesis Tests and Confidence Intervals G1. Confidence Intervals G2. Hypothesis Tests H. OLS Regression (and WLS and GLS) H1. Variable Lists with Automated Category Dummies and Interactions H2. Improved Robust Standard Errors in Finite Samples H3. Weighted Least Squares H4. Feasible Generalized Least Squares I. Post-Estimation Commands I1. Fitted Values, Residuals, and Related Plots I2. Confidence Intervals and Hypothesis Tests I3. Nonlinear Hypothesis Tests I4. Computing Estimated Expected Values for the Dependent Variable I5. Displaying Adjusted R 2 and Other Estimation Results I6. Plotting Any Mathematical Function I7. Influence Statistics I8. Functional Form Test I9. Heteroskedasticity Tests I10. Serial Correlation Tests I11. Variance Inflation Factors I12. Marginal Effects J. Tables of Regression Results

3 J0. Copying and Pasting from Stata to a Word Processor or Spreadsheet Program J1. Tables of Regression Results Using Stata s Built-In Commands J2. Tables of Regression Results Using Add-On Commands J2a. Installing or Accessing the Add-On Commands J2b. Storing Results and Making Tables J2c. Near-Publication-Quality Tables J2d. Understanding the Table Command s Options J2e. Saving Tables as Files J2f. Wide Tables J2g. Storing Additional Results J2h. Clearing Stored Results J2i. More Options and Related Commands K. Data Types, When , and Missing Values L. Results Returned after Commands M. Do-Files and Programs N. Monte-Carlo Simulations O. Doing Things Once for Each Group P. Generating Variables for Time-Series and Panel Data P1. Creating a Time Variable P1a. Time Variable that Starts from a First Time and Increases by 1 at Each Observation P1b. Time Variable from a Date String P1c. Time Variable from Multiple (e.g., Year and Month) Variables P2. Telling Stata You Have Time Series or Panel Data P3. Lags, Forward Leads, and Differences P4. Generating Means and Other Statistics by Individual, Year, or Group Q. Panel Data Statistical Methods Q1. Fixed Effects Using Dummy Variables Q2. Fixed Effects De-Meaning Q3. Other Panel Data Estimators Q4. Time-Series Plots for Multiple Individuals R. Probit and Logit Models R1. Interpreting Coefficients in Probit and Logit Models S. Other Models for Limited Dependent Variables S1. Censored and Truncated Regressions with Normally Distributed Errors S2. Count Data Models S3. Survival Models (a.k.a. Hazard Models, Duration Models, Failure Time Models) T. Instrumental Variables Regression T1. GMM Instrumental Variables Regression T2. Other Instrumental Variables Models U. Time Series Models U1. Autocorrelations U2. Autoregressions (AR) and Autoregressive Distributed Lag (ADL) Models U3. Information Criteria for Lag Length Selection U4. Augmented Dickey Fuller Tests for Unit Roots U5. Forecasting U6. Newey-West Heteroskedastic-and-Autocorrelation-Consistent Standard Errors

4 U7. Dynamic Multipliers and Cumulative Dynamic Multipliers V. System Estimation Commands V1. GMM System Estimators V2. Three-Stage Least Squares V3. Seemingly Unrelated Regression V4. Multivariate Regression W. Flexible Nonlinear Estimation Methods W1. Nonlinear Least Squares W2. Generalized Method of Moments Estimation for Custom Models W3. Maximum Likelihood Estimation for Custom Models X. Data Manipulation Tricks X1. Combining Datasets: Adding Rows X2. Combining Datasets: Adding Columns X3. Reshaping Data X4. Converting Between Strings and Numbers X5. Labels X6. Notes X7. More Useful Commands

5 Useful Stata (Version 12) Commands Preliminaries for RPI Dot.CIO Labs RPI computer labs with Stata include, as of Spring 2013: Sage 4510, Pittsburgh 4114, the VCC Lobby (all Windows PCs), and the VCC North and South labs. To access the Stata program, look under My Computer and open the disk drive X: (probably labeled something like Sage4510$ ), then double-click on the program icon that you see. You must start Stata this way it does not work to double-click on a saved Stata file, because Windows in the labs is not set up to know where to find Stata or even which saved files are Stata files. To access the course disk space, go to: \\hass11.win.rpi.edu\classes\econ If you are logged into the WIN domain you will go right to it. If you are logged in locally on your machine or into anther domain you will be prompted for credentials. Use: username: win\"rcsid" password: "rcspassword" substituting your RCS username for "rcsid" and your RCS password for "rcspassword". Once entered correctly the folder should open up. To access your personal RCS disk space from DotCIO computers, find the icon on the desktop labeled Connect to RCS, double-click on it, and enter your username and password. Your personal disk space will be attached probably as drive H. (Public RCS materials will be attached probably as drive P.) Save Stata do-files to drive H or a memory stick. For handy use when logging in, you may put the web address to attach the course disk space in a file on drive H; that way at the start of a session you can attach the RCS disk space and then open the file with your saved command and run it. A. Loading Data edit Opens the data editor, to type in or paste data. You must close the data editor before you can run any further commands. use "filename.dta" Reads in a Stata-format data file insheet using "filename.txt" Reads in text data. import excel "filename.xlsx", firstrow Reads data from an Excel file s first worksheet, treating the first row as variable names. import excel "filename.xlsx", sheet("price data") firstrow Reads data from the worksheet named price data in an Excel file, treating the first row as variable names. save "filename.dta" Saves the data. Before you load or save files, you may need to change to the right directory. Under the File menu, choose Change Working Directory, or use Stata s cd command. A1. Memory in Stata Version 11 or Earlier As of this writing, Stata is in version 12. If you are using Stata version 11 or earlier, and you will read in a big dataset, then before reading in your data you must tell Stata to make available enough computer memory for your data. For example: set memory 100m Sets memory available for data to 100 megabytes. Clear before setting. If you get a message while using Stata 11 or earlier that there is not enough memory, then clear the existing data (with the clear command), set the memory to a large enough amount, and then re-do your analyses as necessary you should be saving your work in a do file, as noted below in section M). 5

6 B. Variable Lists, If-Statements, and Options Most commands in Stata allow (1) a list of variables, (2) an if-statement, and (3) options. 1. A list of variables consists of the names of the variables, separated with spaces. It goes immediately after the command. If you leave the list blank, Stata assumes where possible that you mean all variables. You can use an asterisk as a wildcard (see Stata s help for varlist). Examples: edit var1 var2 var3 Opens the data editor, just with variables var1, var2, and var3. edit Opens the data editor, with all variables. In later examples, varlist means a list of variables, and varname (or yvar etc.) means one variable. 2. An if-statement restricts the command to certain observations. You can also use an in-statement. Ifand in-statements come after the list of variables. Examples: edit var1 if var2 > 3 Opens the data editor, just with variable var1, only for observations in which var2 is greater than 3. edit if var2 == var3 Opens the data editor, with all variables, only for observations in which var2 equals var3. edit var1 in 10 Opens the data editor, just with var1, just in the 10th observation. edit var1 in 101/200 Opens the data editor, just with var1, in observations edit var1 if var2 > 3 in 101/200 Opens the data editor, just with var1, in the subset of observations that meet the requirement var2 > Options alter what the command does. There are many options, depending on the command get help on the command to see a list of options. Options go after any variable list and if-statements, and must be preceded by a comma. Do not use an additional comma for additional options (the comma works like a toggle switch, so a second comma turns off the use of options!). Examples: use "filename.dta", clear Reads in a Stata-format data file, clearing all data previously in memory! (Without the clear option, Stata refuses to let you load new data if you haven t saved the old data. Here the old data are forgotten and will be gone forever unless you saved some version of them.) save "filename.dta", replace Saves the data, replacing a previously-existing file if any. You will see more examples of options below. C. Lowercase and Uppercase Letters Case matters: if you use an uppercase letter where a lowercase letter belongs, or vice versa, an error message will display. D. Review Window, and Abbreviating Command Names The Review window lists commands you typed previously. Click in the Review window to put a previous command in the Command window (then you can edit it as desired). Double-click to run a command. Another shortcut is that many commands can have their names abbreviated. For example below instead of typing summarize, su will do, and instead of regress, reg will do. E. Viewing and Summarizing Data Here, remember two points from above: (1) leave a varlist blank to mean all variables, and (2) you can use if-statements to restrict the observations used by each command. E1. Just Looking If you want to look at the data but not change them, it is bad practice to use Stata s data editor, as you could accidentally change the data! Instead, use the browser via the button at the top, or by using the following command. Or list the data in the main window. 6

7 browse varlist list varlist Opens the data viewer, to look at data without changing them. Lists data. If there s more than 1 screenful, press space for the next screen, or q to quit listing. E2. Mean, Variance, Number of Non-missing Observations, Minimum, Maximum, Etc. summarize varlist See summary information for the variables listed. summarize varlist, detail See detailed summary information for the variables listed. by byvars: summarize varlist See summary information separately for each group of unique values of the variables in byvars. For example, by gender: summarize wage. inspect varlist See a mini-histogram, and numbers of positives / zeroes / negatives, integers / non-integers, and missing data values, for each variable. codebook varlist Another view of information about variables. E3. Tabulations, Histograms, Density Function Estimates tabulate varname Creates a table listing the number of observations having each different value of the variable varname. tabulate var1 var2 Creates a two-way table listing the number of observations in each row and column. tabulate var1 var2, exact Creates the same two-way table, and carries out a statistical test of the null hypothesis that var1 and var2 are independent. The test is exact, in that it does not rely on convergence to a distribution. tabulate var1 var2, chi2 Same as above, except the statistical test relies on asymptotic convergence to a normal distribution. If you have lots of observations, exact tests can take a long time and can run out of available computer memory; if so, use this test instead. histogram varname Plots a histogram of the specified variable. histogram varname, bin(#) normal The bin(#) option specifies the number of bars. The normal option overlays a normal probability distribution with the same mean and variance. kdensity varname, normal Creates a kernel density plot, which is an estimate of the pdf that generated the data. The normal option lets you overlay a normal probability distribution with the same mean and variance. E4. Scatter Plots and Other Plots scatter yvar xvar Plots data, with yvar on the vertical axis and xvar on the horizontal axis. scatter yvar1 yvar2 xvar Plots multiple variables on the vertical axis and xvar on the horizontal axis. Stata has lots of other possibilities for graphs, with an inch-and-a-half-thick manual. For a quick web-based introduction to some of Stata s graphics commands, try the Graphics section of this web page: Or go to Stata s pdf manuals and look at [G] Graph intro, viewing especially the section labeled A quick tour. Or use Stata s Help menu and choose Stata Command, type graph_intro, and press return. Scroll down past the table of contents and read the section labeled A quick tour. 7

8 E5. Correlations and Covariances The following commands compute the correlations and covariances between any list of variables. Note that if any of the variables listed have missing values in some rows, those rows are ignored in all calculations. correlate var1 var2 Computes the sample correlations between variables. correlate var1 var2, covariance Computes the sample covariances between variables. Sometimes you have missing values in some rows, but want to use all available data wherever possible i.e., for some correlations but not others. For example, if you have data on health, nutrition, and income, and income data are missing for 90% of your observations, then you could compute the correlation of health with nutrition using all of the observations, while computing the correlations of health with income and of nutrition with income for just the 10% of observations that have income data. These are called pairwise correlations and can be obtained as follows: pwcorr var1 var2 Computes pairwise sample correlations between variables. F. Generating and Changing Variables A variable in Stata is a whole column of data. You can generate a new column of data using a formula, and you can replace existing values with new ones. Each time you do this, the calculation is done separately for every observation in the sample, using the same formula each time. F1. Generating Variables generate newvar = Generate a new variable using the formula you enter in place of. Examples follow. gen f = m * a Remember, Stata allows abbreviations: gen means generate. gen xsquared = x^2 gen logincome = log(income) Use log() or ln() for a log-base-e, or log10() for log-base-10. gen q = exp(z) / (1 exp(z)) gen a = abs(cos(x)) This uses functions for absolute value, abs(), and cosine, cos(). Many more functions are available get help for functions for a list. F2. Missing Data Be aware of missing data in Stata. Missing data can result when you compute a number whose answer is not defined; for example, if you use gen logincome = log(income) then logincome will be missing for any observation in which income is zero or negative. Missing data can also result during data collection; for example, in data on publicly listed companies often R&D expenditures data are unavailable. Missing data can be entered in Stata by using a period instead of a number. When you list data, a period likewise indicates a missing datum. Missing data can be used in Stata calculations. For example, you can check whether logincome is missing, and only list the data for observations where this is true: list if logincome==. List only observations in which logincome is missing. A missing datum counts as infinity when making comparisons. For example, if logincome is not missing, then it is less than infinity, so you could create a variable that tells whether logincome is non-missing by checking whether logincome is less the missing value code: gen notmiss = logincome<. If logincome is less than infinity, then notmiss equals true which is recorded as 1, but otherwise notmiss equals false which is recorded as 0. 8

9 Should you need to distinguish reasons why data are missing, you could use Stata s extended missing value codes. These codes are written.a,.b,.c,,.z. They all count as infinity when compared versus normal numbers, but compared to each other they are ranked as. <.a <.b <.c < <.z. For this reason, to check whether a number in variable varname is missing you should use not varname==. but varname>=. F3. True-False Variables Below are examples of how to create true-false variables in Stata. When you create these variables, true will be 1, and false will be 0. When you ask Stata to check whether a number means true or false, then 0 will mean false and anything else (including a missing value) will mean true. The basic operators used when creating true-false values are == (check whether something is equal), <, <=, >, >=,! ( not which changes false to true and true to false), and!= (check whether something is not equal). You can also use & and to mean logical and and or respectively, and you can use parentheses as needed to group parts of your expressions or equations. When creating true-false values, as noted above, missing values in Stata work like infinity. So if age is missing and you use gen old = age >= 18, then old gets set to 1 when really you don t know whether or not someone is old. Instead you should gen old = age >= 18 if age<.. This is discussed more in section K below. When using true-false values, 0 is false and anything else including missing values counts as true. So!(0) = 1,!(1) = 0,!(3) = 0, and!(.) = 0. Again, use an if-statement to ensure you generate non-missing values only where appropriate. With these fundamentals in mind, here are examples of how to create true-false data in Stata: gen young = age < 18 if age<. If age is less than 18, then young is true, represented in Stata as 1. If age is 18 or over, then young is false, represented in Stata as 0. The calculation is done only if age is less than missing, i.e. nonmissing (see above), so that no answer (a missing value) will be generated if the age is unknown. gen old = age >= 18 if age<. If age is 18 or higher, this yields 1, otherwise this yields 0 (but missing-value ages result in missing values for old). gen age18 = age == 18 if age<. Use a single equal sign to set a variable equal to something. Use a double equal sign to check whether the left hand side equals the right hand side. In this case, age18 is created and equals 1 if the observation has age 18 and 0 if it does not. gen youngwoman = age < 18 & female==1 if age<. & female<. Here the ampersand, &, means a logical and. The variable youngwoman is created and equals 1 if and only if age is less than 18 and also female equals one; otherwise it equals 0. Here, the if condition ensures that the answer will be missing if either age or female is missing. gen youngorwoman = age<18 female==1 if age<. & female<. Here the vertical bar,, means a logical or. The variable youngorwoman is created and equals 1 if age is less than 18 or if female equals one; otherwise it equals 0. Here, the if condition ensures that the answer will be missing if either age or female is missing. You could improve on this ifcondition to make the answer non-missing if the person is known to be young but has a missing value for female, or if the person is known to be female but has a missing value for age. To do so you 9

10 could use: gen youngorwoman = age<18 female==1 if (age<. & female<.) (age<18) (female==1). gen agenot18 = age!= 18 if age<. The!= symbol means not equal to. gen notold =!old if old<. The! symbol is pronounced not and switches true to false or false to true. The result is the same as the variable young above. F4. Random Numbers gen r1 = runiform() Random numbers, uniformly distributed between 0 and 1. gen r2 = rnormal() Random numbers, with a standard normal distribution. gen r3 = rnormal(5,2) Random numbers, with a normal distribution using mean 5 and standard deviation 2. Alternatively, you could use gen r3 = * rnormal(), or gen r3 = * invnorm(runiform()) gen r4 = rchi2(27) Random numbers, with a chi-squared distribution with 27 degrees of freedom. gen r5 = rt(27) Random numbers, with a t-distribution with 27 degrees of freedom. For other random number distributions use Stata s menu to get help for functions. You can also set the seed for random number generation (e.g., set seed 1234 ), to ensure that a reproducible sequence of random numbers will result thereafter that way if you rerun your analyses later you can get exactly the same results. F5. Replacing Values of Variables replace agesquared = age^2 Changes the value of the variable agesquared, to equal age squared. This would be useful if you had made a mistake when you first created the variable. replace young = age < 16 if age<. Changes the value of the variable young, to equal 1 if and only if age is less than 16, and 0 otherwise. The if age<. Ensures that replacements are only made when values of age are nonmissing see the comments about missing values in sections F2 and F3 above. replace young = cond(age<., age < 16,.) Here is another way to ensure that the answer is missing if age is missing. To do this, we use Stata s conditional function, cond(a,b,c), which checks whether a is true and then returns b if a is true or c if a is not true (see F7 below). replace young = 0 if age>=16 & age<18 Changes the value of the variable young to 0, but only if age is at least 16 and less than 18. That is, no change is made if age is less than 16 or if age is at least 18. F6. Getting Rid of Variables drop varlist Gets rid of all variables in the list. clear Gets rid of all variables, as well as labels which are discussed in section X5. clear all Gets rid of not just variables and labels, but also all sorts of things that we haven t discussed yet: matrices, scalars, constraints, clusters, postfile declarations, returned results, programs, mata contents, and timer settings, and closes all open files. 10

11 F7. If-then-else Formulas gen val = cond(a, b, c) Stata s cond(if, then, else) works much like Excel s IF(if, then, else). With the statement cond(a,b,c), Stata checks whether a is true and then returns b if a is true or c if a is not true. gen realwage = cond(year==1992, wage*(188.9/140.3), wage) Creates a variable that uses one formula for observations in which the year is 1992, or a different formula if the year is not This particular example would be useful if you have data from two years only, 1992 and 2004, and the consumer price index was in 1992 and in 2004; then the example given here would compute the real wage by rescaling 1992 wages while leaving 2004 wages the same. F8. Quick Calculations display display ( )/12.7 display normal(1.96) Calculate the formula you type in, and display the result. Examples follow. Compute the probability to the left of 1.96 using the cumulative standard normal distribution. display F(10,9000,2.32) Compute the probability that an F-distributed number, with 10 and 9000 degrees of freedom, is less than or equal to Also, there is a function Ftail(n1,n2,f) = 1 F(n1,n2,f). Similarly, you can use ttail(n,t) for the probability that T>t, for a t-distributed random variable T with n degrees of freedom. F9. More For functions available in equations in Stata, use Stata s Help menu, choose Stata Command, and enter functions. To generate variables separately for different groups of observations, see the commands in sections O and P4. For time-series and panel data, see section P, especially the notations for lags, leads, and differences in section P3. If you need to refer to a specific observation number, use a reference like x[3], meaning the valuable of the variable x in the 3rd observation. In Stata _n means the current observation (when using generate or replace), so that for example x[_n-1] means the value of x in the preceding observation, and _N means the number of observations, so that x[_n] means the value of x in the last observation. G. Means: Hypothesis Tests and Confidence Intervals G1. Confidence Intervals ci varname ci varname, level(#) by varlist: ci varname Confidence interval for the mean of varname (using asymptotic normal distribution). Confidence interval at #%. For example, use 99 for a 99% confidence interval. Compute confidence intervals separately for each unique set of values of the variables in varlist. by female: ci workhours Compute confidence intervals for the mean of workhours, separately for people who are males versus females. Other commands also report confidence intervals, and may be preferable because they do more, such as computing a confidence interval for the difference in means between by groups (e.g., 11

12 between men and women). See section G2. (Also, Stata s mean command reports confidence intervals.) G2. Hypothesis Tests ttest varname == # Test the hypothesis that the mean of a variable is equal to some number, which you type instead of the number sign #. ttest varname1 == varname2 Test the hypothesis that the mean of one variable equals the mean of another variable. ttest varname, by(groupvar) Test the hypothesis that the mean of a single variable is the same for all groups. The groupvar must be a variable with a distinct value for each group. For example, groupvar might be year, to see if the mean of a variable is the same in every year of data. H. OLS Regression (and WLS and GLS) regress yvar xvarlist Regress the dependent variable yvar on the independent variables xvarlist. For example: regress y x, or regress y x1 x2 x3. regress yvar xvarlist, vce(robust) Regress, but this time compute robust (Eicker-Huber-White) standard errors. We are always using the vce(robust) option in ECON-4570 Econometrics, because we want consistent (i.e,, asymptotically unbiased) results, but we do not want to have to assume homoskedasticity and normality of the random error terms. So if you are in ECON-4570 Econometrics, remember always to specify the vce(robust) option after estimation commands. The vce stands for variance-covariance estimates (of the estimated model parameters). regress yvar xvarlist, vce(robust) level(#) Regress with robust standard errors, and this time change the confidence interval to #% (e.g. use 99 for a 99% confidence interval). Occasionally you will need to regress without vce(robust), to allow post-regression tests that assume homoscedasticity. Notably, Stata displays adjusted R 2 values only under the assumption of homoscedasticity, since the usual interpretation of R 2 presumes homoscedasticity. However, another way to see the adjusted R 2 after using regress, vce(robust) is to type display e(r2_a) ; see section I5. H1. Variable Lists with Automated Category Dummies and Interactions Stata (beginning with Stata 11) allows you enter variable lists that automatically create dummies for categories as well as interaction variables. For example, suppose you have a variable named usstate numbered 1 through 50 for the fifty U.S. states, and you want to include forty-nine 0-1 dummy variables that allow for differences between the first state (Alabama, say) and other states. Then you could simply include i.usstate in the xvarlist for your regression. Similarly, suppose you want to create the interaction between two variables, named age (a continuous variable) and male (a 0-1 dummy variable). Then, including c.age#i.male includes the interaction (the multiple of the two variables) in the regression. The c. in front of age indicates that it is a continuous variable, whereas the i. in front of male indicates that it is a 0-1 dummy variable. Including c.age#i.usstate adds 49 variables to the model, age times each of the 49 state dummies. Use ## instead of # to add full interactions, for example c.age##i.male means age, male, and age male. Similarly, c.age##i.usstate means age, 49 state dummies, and 49 state dummies multiplied by age. 12

13 You can use # to create polynomials. For example, age age#age age#age#age is a thirdorder polynomial, with variables age and age 2 and age 3. Having done this, you can use Stata s margins command to compute marginal effects: the average value of the derivatives d(y)/d(age) across all observations in the sample. This works even if your regression equation includes interactions of age with other variables. Here are some examples using automated category dummies and interactions, termed factor variables in the Stata manuals (see the User s Guide U11.4 for more information): reg yvar x1 i.x2, vce(robust) Includes a 0-1 dummy variables for the groups indicated by unique values of variable x2. reg wage c.age i.male c.age#i.male, vce(robust) Regress wage on age, male, and age male. reg wage c.age##i.male, vce(robust) Regress wage on age, male, and age male. reg wage c.age##i.male c.age#c.age, vce(robust) Regress wage on age, male, age male, and age 2. reg wage c.age##i.male c.age#c.age c.age#c.age#i.male, vce(robust) Regress wage on age, male, age male, age 2, and age 2 male. reg wage c.age##i.usstate c.age#c.age c.age#c.age#i.usstate, vce(robust) Regress wage on age, 49 state dummies, 49 variable that are age statedummy k, age 2, and 49 variable that are age 2 statedummy k (k=1,,49). Speed Tip: Don t generate lots of dummy variables and interactions instead use this factor notation to compute your dummy variables and interactions on the fly during statistical estimation. This usually is much faster and saves lots of memory, if you have a really big dataset. H2. Improved Robust Standard Errors in Finite Samples For robust standard errors, an apparent improvement is possible. Davidson and MacKinnon * report two variance-covariance estimation methods that seem, at least in their Monte Carlo simulations, to converge more quickly, as sample size n increases, to the correct variancecovariance estimates. Thus their methods seem better, although they require more computational time. Stata by default makes Davidson and MacKinnon s recommended simple degrees of freedom correction by multiplying the estimated variance matrix by n/(n-k). However, students in ECON-6570 Advanced Econometrics learn about an alternative in which the squared residuals are rescaled. To use this formula, specify vce(hc2) instead of vce(robust), to use the approach discussed in Hayashi p. 125 formula using d=1 (or in Greene s text, 6 th edition, on p. 164). An alternative is vce(hc3) instead of vce(robust) (Hayashi page 125 formula using d=2 or Greene p. 164 footnote 15). H3. Weighted Least Squares Students in ECON-6570 Advanced Econometrics learn about (variance-)weighted least squares. If you know (to within a constant multiple) the variances of the error terms for all observations, this yields more efficient estimates (OLS with robust standard errors works properly using asymptotic methods but is not the most efficient estimator). Suppose you have, stored in a variable sdvar, a reasonable estimate of the standard deviation of the error term for each observation. Then weighted least squares can be performed as follows: vwls yvar xvarlist, sd(sdvar) * R. Davidson and J. MacKinnon, Estimation and Inference in Econometrics, Oxford: Oxford University Press, 1993, section

14 H4. Feasible Generalized Least Squares Students in ECON-6570 Advanced Econometrics learn about feasible generalized least squares (Greene pp and ). The groupwise heteroskedasticity model can be estimated by computing the estimated standard deviation for each group using Greene s (6 th edition) equation 8-36 (p. 173): do the OLS regression, get the residuals, and use by groupvars: egen estvar = mean(residual^2) with appropriate variable names in place of the italicized words, then gen estsd = sqrt(estvar), then use this estimated standard deviation to carry out weighted least squares as shown above. (To get the residuals, see section I1 below). Or, if your independent variables are just the group variables (categorical variables that indicate which observation is in each group) you can use the command: vwls yvar xvarlist The multiplicative heteroskedasticity model is available via a free third-party add-on command for Stata. See section J2a of this document for how to use add-on commands. If you have your own copy of Stata, just use the help menu to search for sg77 and click the appropriate link to install. A discussion of these commands was published in the Stata Technical Bulletin volume 42, available online at: The command then can be estimated like this (see the help file and Stata Technical Bulletin for more information): reghv yvar xvarlist, var(zvarlist) robust twostage I. Post-Estimation Commands Commands described here work after OLS regression. They sometimes work after other estimation commands, depending on the command. I1. Fitted Values, Residuals, and Related Plots predict yhatvar predict rvar, residuals After a regression, create a new variable, having the name you enter here, that contains for each observation its fitted value y ˆi. After a regression, create a new variable, having the name you enter here, that contains for each observation its residual u ˆi (in the notation of Hayashi and most books u ˆi is written e =ε ˆ ). scatter y yhat x Plot variables named y and yhat versus x. scatter resids x It is wise to plot your residuals versus each of your x-variables. Such residual plots may reveal a systematic relationship that your analysis has ignored. It is also wise to plot your residuals versus the fitted values of y, again to check for a possible nonlinearity that your analysis has ignored. rvfplot Plot the residuals versus the fitted values of y. rvpplot Plot the residuals versus a predictor (x-variable). For more such commands, see the nice [R] regress postestimation section of the Stata manuals. This manual section is a great place to learn techniques to check the trustworthiness of regression results always a good idea! I2. Confidence Intervals and Hypothesis Tests For a single coefficient in your statistical model, the confidence interval is already reported in the table of regression results, along with a 2-sided t-test for whether the true coefficient is zero. However, you may need to carry out F-tests, as well as compute confidence intervals and t-tests for linear combinations of coefficients in the model. Here are example commands. Note that when i i 14

15 a variable name is used in this subsection, it really refers to the coefficient (the β k ) in front of that variable in the model equation. lincom logpl+logpk+logpf Compute the estimated sum of three model coefficients, which are the coefficients in front of the variables named logpl, logpk, and logpf. Along with this estimated sum, carry out a t-test with the null hypothesis being that the linear combination equals zero, and compute a confidence interval. lincom 2*logpl+1*logpk-1*logpf Like the above, but now the formula is a different linear combination of regression coefficients. lincom 2*logpl+1*logpk-1*logpf, level(#) As above, but this time change the confidence interval to #% (e.g. use 99 for a 99% confidence interval). test logpl+logpk+logpf==1 Test the null hypothesis that the sum of the coefficients of variables logpl, logpk, and logpf, totals to 1. This only makes sense after a regression involving variables with these names. After OLS regression, this is an F-test. More generally, it is a Wald test. test (logq2==logq1) (logq3==logq1) (logq4==logq1) (logq5==logq1) Test the null hypothesis that four equations are all true simultaneously: the coefficient of logq2 equals the coefficient of logq1, the coefficient of logq3 equals the coefficient of logq1, the coefficient of logq4 equals the coefficient of logq1, and the coefficient of logq5 equals the coefficient of logq1; i.e., they are all equal to each other. After OLS regression, this is an F-test. More generally, it is a Wald test. test x3 x4 x5 Test the null hypothesis that the coefficient of x3 equals 0 and the coefficient of x4 equals 0 and the coefficient of x5 equals 0. After OLS regression, this is an F-test. More generally, it is a Wald test. I3. Nonlinear Hypothesis Tests Students in ECON-6570 Advanced Econometrics learn about nonlinear hypothesis tests. After estimating a model, you could do something like the following: testnl _b[popdensity]*_b[landarea] = 3000 Test a nonlinear hypothesis. Note that coefficients must be specified using _b, whereas the linear test command lets you omit the _b[]. testnl (_b[mpg] = 1/_b[weight]) (_b[trunk] = 1/_b[length]) For multi-equation tests you can put parentheses around each equation (or use multiple equality signs in the same equation; see the Stata manual, [R] testnl, for examples). I4. Computing Estimated Expected Values for the Dependent Variable di _b[xvarname] Display the value of an estimated coefficient after a regression. Use the variable name _cons for the estimated constant term. Of course there s no need just to display these numbers, but the good thing is that you can use them in formulae. See the next example. di _b[_cons] + _b[age]*25 + _b[female]*1 After a regression of y on age and female (but no other independent variables), compute the estimated value of y for a 25-year-old female. See also the predict command mentioned above in section I1, and the margins command. 15

16 I5. Displaying Adjusted R 2 and Other Estimation Results 2 display e(r2_a) After a regression, the adjusted R-squared, R, can be looked up as 2 e(r2_a). Or get R as in section J below. (Stata does not report the adjusted R 2 when you do regression with robust standard errors, because robust standard errors are used when the variance (conditional on your right-hand-side variables) is thought to differ between observations, and this would alter the standard interpretation of the adjusted R 2 statistic. Nonetheless, people often report the adjusted R 2 in this situation anyway. It may still be a useful indicator, and often the (conditional) variance is still reasonably close to constant across observations, so that it can be thought of as an approximation to the adjusted R 2 statistic that would occur if the (conditional) variance were constant.) ereturn list Display all results saved from the most recent model you estimated, including the adjusted R 2 and other items. Items that are matrices are not displayed; you can see them with the command matrix list e(matrixname). Study Tip: Students are strongly advised to understand the meanings of the two main sets of estimates that come out of regression models, (a) the coefficient estimates, and (b) the estimated variances and covariances of those coefficient estimates: matrix list e(b) List the coefficient estimates of your recent regression. matrix list e(v) List the estimated variances and covariances of your coefficient estimates in your recent regression. This is a symmetric matrix, so the part above the diagonal is not shown. The diagonal entries are estimated variances of your coefficient estimates (take square roots to get the standard errors), and the off-diagonal entries are estimated covariances. Once you understand what both of these are, you ll have a much better understanding of what regression does (and you ll probably never need these particular matrix list commands!). I6. Plotting Any Mathematical Function twoway function y=exp(-x/6)*sin(x), range( ) Plot a function graphically, for any function of a single variable x. A command like this may be useful to examine how a polynomial in one regressor (x) affects the dependent variable in a regression, without specifying values for other variables. The variable name on the right hand side must be x do not use the names of variables in your data, or some values of those variables may be plugged in instead! If you are getting funny looking results, you may have used a different variable name instead of x; the right-hand variable must be named x. I7. Influence Statistics Influence statistics give you a sense of how much your estimates are sensitive to particular observations in the data. This may be particularly important if there might be errors in the data. After running a regression, you can compute how much different the estimated coefficient of any 16

17 given variable would be if any particular observation were dropped from the data. To do so for one variable, for all observations, use this command: predict newvarname, dfbeta(varname) Computes the influence statistic ( DFBETA ) for varname: how much the estimated coefficient of varname would change if each observation were excluded from the data. The change divided by the standard error of varname, for each observation i, is stored in the ith observation of the newly created variable newvarname. Then you might use summarize newvarname, detail to find out the largest values by which the estimates would change (relative to the standard error of the estimate). If these are large (say close to 1 or more), then you might be alarmed that one or more observations may completely change your results, so you had better make sure those results are valid or else use a more robust estimation technique (such as robust regression, which is not related to robust standard errors, or quantile regression, both available in Stata). If you want to compute influence statistics for many or all regressors, Stata s dfbeta command lets you do so in one step. I8. Functional Form Test It is sometimes important to ensure that you have the right functional form for variables in your regression equation. Sometimes you don t want to be perfect, you just want to summarize roughly how some independent variables affect the dependent variable. But sometimes, e.g., if you want to control fully for the effects of an independent variable, it can be important to get the functional form right (e.g., by adding polynomials and interactions to the model). To check whether the functional form is reasonable and consider alternative forms, it helps to plot the residuals versus the fitted values and versus the predictors, as shown in section I1 above. Another approach is to formally test the null hypothesis that the patterns in the residuals cannot be explained by powers of the fitted values. One such formal test is the Ramsey RESET test: estat ovtest Ramsey s (1969) regression equation specification error test. I9. Heteroskedasticity Tests Students in ECON-6570 Advanced Econometrics learn about heteroskedasticity tests. After running a regression, you can carry out White s test for heteroskedasticity using the command: estat imtest, white Heteroskedasticity tests including White test. You can also carry out the test by doing the auxiliary regression described in the textbook; indeed, this is a better way to understand how the test works. Note, however, that there are many other heteroskedasticity tests that may be more appropriate. Stata s imtest command also carries out other tests, and the commands hettest and szroeter carry out different tests for heteroskedasticity. The Breusch-Pagan Lagrange multiplier test, which assumes normally distributed errors, can be carried out after running a regression, by using the command: estat hettest, normal Heteroskedasticity test - Breusch-Pagan Lagrange mulitplier. Other tests that do not require normally distributed errors include: estat hettest, iid Heteroskedasticity test Koenker s (1981) s score test, assumes iid errors. estat hettest, fstat Heteroskedasticity test Wooldridge s (2006) F-test, assumes iid errors. 17

18 estat szroeter, rhs mtest(bonf) Heteroskedasticity test Szroeter (1978) rank test for null hypothesis that variance of error term is unrelated to each variable. estat imtest Heteroskedasticity test Cameron and Trivedi (1990), also includes tests for higher-order moments of residuals (skewness and kurtosis). For further information see the Stata manuals. See also the ivhettest command described in section T1 of this document. This makes available the Pagan-Hall test which has advantages over the results from estat imtest. I10. Serial Correlation Tests Students in ECON-6570 Advanced Econometrics learn about tests for serial correlation. To carry out these tests in Stata, you must first tsset your data as described in section P of this document (see also section U). For a Breusch-Godfrey test where, say, p = 3, do your regression and then use Stata s estat bgodfrey command: estat bgodfrey, lags(1 2 3) Heteroskedasticity tests including White test. Other tests for serial correlation are available. For example, the Durbin-Watson d-statistic is available using Stata s estat dwatson command. However, as Hayashi (p. 45) points out, the Durbin-Watson statistic assumes there is no endogeneity even under the alternative hypothesis, an assumption which is typically violated if there is serial correlation, so you really should use the Breusch-Godfrey test instead (or use Durbin s alternative test, estat durbinalt ). For the Box- Pierce Q in Hayashi s or the modified Box-Pierce Q in Hayashi s , you would need to compute them using matrices. The Ljung-Box test is available in Stata by using the command: wntestq varname, lags(#) Ljung-Box portmanteau (Q) test for white noise. I11. Variance Inflation Factors Students in ECON-6570 Advanced Econometrics may use variance inflation factors (VIFs), which show the multiple by which the estimated variance of each coefficient estimate is larger because of non-orthogonality with other variables in the model. To compute the VIFs, use: estat vif After a regression, display variance inflation factors. I12. Marginal Effects After using regress or almost any other estimation command, you can compute marginal effects using the margins command (available beginning in Stata 11). Marginal effects are d(y)/d(x k ) for continuous variables x k, or delta-y/delta-x k for discrete variables x k. In particular, these are reported for the average individual in the sample. Use factor variables when writing the list of variables in the model, so that Stata knows the way in which each variable contributes to the model see section H1 above. Here is a simple example, but you should read the Stata manual entry [R] margins if you plan to use the margins command much. margins age After a regression where the x-variables involve age, compute d(y)/d(age) on average among individuals in the sample. J. Tables of Regression Results This section will make your work much easier! You can store results of regressions, and use previously stored results to display a table. This makes it much easier to create tables of regression results in Word. By copying and pasting, most of the work of creating the table is trivial, without errors from typing wrong numbers. Stata has built-in commands for making tables, and you should try them to see how they work, as described in section J1. In practice it will be much easier to use add-on commands, that you install, discussed in section J2. 18

Please follow the directions once you locate the Stata software in your computer. Room 114 (Business Lab) has computers with Stata software

Please follow the directions once you locate the Stata software in your computer. Room 114 (Business Lab) has computers with Stata software STATA Tutorial Professor Erdinç Please follow the directions once you locate the Stata software in your computer. Room 114 (Business Lab) has computers with Stata software 1.Wald Test Wald Test is used

More information

NCSS Statistical Software Principal Components Regression. In ordinary least squares, the regression coefficients are estimated using the formula ( )

NCSS Statistical Software Principal Components Regression. In ordinary least squares, the regression coefficients are estimated using the formula ( ) Chapter 340 Principal Components Regression Introduction is a technique for analyzing multiple regression data that suffer from multicollinearity. When multicollinearity occurs, least squares estimates

More information

Directions for using SPSS

Directions for using SPSS Directions for using SPSS Table of Contents Connecting and Working with Files 1. Accessing SPSS... 2 2. Transferring Files to N:\drive or your computer... 3 3. Importing Data from Another File Format...

More information

Overview of Violations of the Basic Assumptions in the Classical Normal Linear Regression Model

Overview of Violations of the Basic Assumptions in the Classical Normal Linear Regression Model Overview of Violations of the Basic Assumptions in the Classical Normal Linear Regression Model 1 September 004 A. Introduction and assumptions The classical normal linear regression model can be written

More information

Simple Linear Regression Inference

Simple Linear Regression Inference Simple Linear Regression Inference 1 Inference requirements The Normality assumption of the stochastic term e is needed for inference even if it is not a OLS requirement. Therefore we have: Interpretation

More information

Forecasting in STATA: Tools and Tricks

Forecasting in STATA: Tools and Tricks Forecasting in STATA: Tools and Tricks Introduction This manual is intended to be a reference guide for time series forecasting in STATA. It will be updated periodically during the semester, and will be

More information

Simple Regression Theory II 2010 Samuel L. Baker

Simple Regression Theory II 2010 Samuel L. Baker SIMPLE REGRESSION THEORY II 1 Simple Regression Theory II 2010 Samuel L. Baker Assessing how good the regression equation is likely to be Assignment 1A gets into drawing inferences about how close the

More information

January 26, 2009 The Faculty Center for Teaching and Learning

January 26, 2009 The Faculty Center for Teaching and Learning THE BASICS OF DATA MANAGEMENT AND ANALYSIS A USER GUIDE January 26, 2009 The Faculty Center for Teaching and Learning THE BASICS OF DATA MANAGEMENT AND ANALYSIS Table of Contents Table of Contents... i

More information

Data Analysis Tools. Tools for Summarizing Data

Data Analysis Tools. Tools for Summarizing Data Data Analysis Tools This section of the notes is meant to introduce you to many of the tools that are provided by Excel under the Tools/Data Analysis menu item. If your computer does not have that tool

More information

MULTIPLE REGRESSION AND ISSUES IN REGRESSION ANALYSIS

MULTIPLE REGRESSION AND ISSUES IN REGRESSION ANALYSIS MULTIPLE REGRESSION AND ISSUES IN REGRESSION ANALYSIS MSR = Mean Regression Sum of Squares MSE = Mean Squared Error RSS = Regression Sum of Squares SSE = Sum of Squared Errors/Residuals α = Level of Significance

More information

Gamma Distribution Fitting

Gamma Distribution Fitting Chapter 552 Gamma Distribution Fitting Introduction This module fits the gamma probability distributions to a complete or censored set of individual or grouped data values. It outputs various statistics

More information

Introduction to Regression and Data Analysis

Introduction to Regression and Data Analysis Statlab Workshop Introduction to Regression and Data Analysis with Dan Campbell and Sherlock Campbell October 28, 2008 I. The basics A. Types of variables Your variables may take several forms, and it

More information

SYSTEMS OF REGRESSION EQUATIONS

SYSTEMS OF REGRESSION EQUATIONS SYSTEMS OF REGRESSION EQUATIONS 1. MULTIPLE EQUATIONS y nt = x nt n + u nt, n = 1,...,N, t = 1,...,T, x nt is 1 k, and n is k 1. This is a version of the standard regression model where the observations

More information

Regression Analysis (Spring, 2000)

Regression Analysis (Spring, 2000) Regression Analysis (Spring, 2000) By Wonjae Purposes: a. Explaining the relationship between Y and X variables with a model (Explain a variable Y in terms of Xs) b. Estimating and testing the intensity

More information

Clustering in the Linear Model

Clustering in the Linear Model Short Guides to Microeconometrics Fall 2014 Kurt Schmidheiny Universität Basel Clustering in the Linear Model 2 1 Introduction Clustering in the Linear Model This handout extends the handout on The Multiple

More information

The following postestimation commands for time series are available for regress:

The following postestimation commands for time series are available for regress: Title stata.com regress postestimation time series Postestimation tools for regress with time series Description Syntax for estat archlm Options for estat archlm Syntax for estat bgodfrey Options for estat

More information

Note 2 to Computer class: Standard mis-specification tests

Note 2 to Computer class: Standard mis-specification tests Note 2 to Computer class: Standard mis-specification tests Ragnar Nymoen September 2, 2013 1 Why mis-specification testing of econometric models? As econometricians we must relate to the fact that the

More information

25 Working with categorical data and factor variables

25 Working with categorical data and factor variables 25 Working with categorical data and factor variables Contents 25.1 Continuous, categorical, and indicator variables 25.1.1 Converting continuous variables to indicator variables 25.1.2 Converting continuous

More information

Stata Walkthrough 4: Regression, Prediction, and Forecasting

Stata Walkthrough 4: Regression, Prediction, and Forecasting Stata Walkthrough 4: Regression, Prediction, and Forecasting Over drinks the other evening, my neighbor told me about his 25-year-old nephew, who is dating a 35-year-old woman. God, I can t see them getting

More information

ECON 142 SKETCH OF SOLUTIONS FOR APPLIED EXERCISE #2

ECON 142 SKETCH OF SOLUTIONS FOR APPLIED EXERCISE #2 University of California, Berkeley Prof. Ken Chay Department of Economics Fall Semester, 005 ECON 14 SKETCH OF SOLUTIONS FOR APPLIED EXERCISE # Question 1: a. Below are the scatter plots of hourly wages

More information

From the help desk: Bootstrapped standard errors

From the help desk: Bootstrapped standard errors The Stata Journal (2003) 3, Number 1, pp. 71 80 From the help desk: Bootstrapped standard errors Weihua Guan Stata Corporation Abstract. Bootstrapping is a nonparametric approach for evaluating the distribution

More information

Multivariate Normal Distribution

Multivariate Normal Distribution Multivariate Normal Distribution Lecture 4 July 21, 2011 Advanced Multivariate Statistical Methods ICPSR Summer Session #2 Lecture #4-7/21/2011 Slide 1 of 41 Last Time Matrices and vectors Eigenvalues

More information

SPSS Manual for Introductory Applied Statistics: A Variable Approach

SPSS Manual for Introductory Applied Statistics: A Variable Approach SPSS Manual for Introductory Applied Statistics: A Variable Approach John Gabrosek Department of Statistics Grand Valley State University Allendale, MI USA August 2013 2 Copyright 2013 John Gabrosek. All

More information

KSTAT MINI-MANUAL. Decision Sciences 434 Kellogg Graduate School of Management

KSTAT MINI-MANUAL. Decision Sciences 434 Kellogg Graduate School of Management KSTAT MINI-MANUAL Decision Sciences 434 Kellogg Graduate School of Management Kstat is a set of macros added to Excel and it will enable you to do the statistics required for this course very easily. To

More information

Doing Multiple Regression with SPSS. In this case, we are interested in the Analyze options so we choose that menu. If gives us a number of choices:

Doing Multiple Regression with SPSS. In this case, we are interested in the Analyze options so we choose that menu. If gives us a number of choices: Doing Multiple Regression with SPSS Multiple Regression for Data Already in Data Editor Next we want to specify a multiple regression analysis for these data. The menu bar for SPSS offers several options:

More information

Introduction to Statistical Computing in Microsoft Excel By Hector D. Flores; hflores@rice.edu, and Dr. J.A. Dobelman

Introduction to Statistical Computing in Microsoft Excel By Hector D. Flores; hflores@rice.edu, and Dr. J.A. Dobelman Introduction to Statistical Computing in Microsoft Excel By Hector D. Flores; hflores@rice.edu, and Dr. J.A. Dobelman Statistics lab will be mainly focused on applying what you have learned in class with

More information

Auxiliary Variables in Mixture Modeling: 3-Step Approaches Using Mplus

Auxiliary Variables in Mixture Modeling: 3-Step Approaches Using Mplus Auxiliary Variables in Mixture Modeling: 3-Step Approaches Using Mplus Tihomir Asparouhov and Bengt Muthén Mplus Web Notes: No. 15 Version 8, August 5, 2014 1 Abstract This paper discusses alternatives

More information

Chicago Booth BUSINESS STATISTICS 41000 Final Exam Fall 2011

Chicago Booth BUSINESS STATISTICS 41000 Final Exam Fall 2011 Chicago Booth BUSINESS STATISTICS 41000 Final Exam Fall 2011 Name: Section: I pledge my honor that I have not violated the Honor Code Signature: This exam has 34 pages. You have 3 hours to complete this

More information

From the help desk: Swamy s random-coefficients model

From the help desk: Swamy s random-coefficients model The Stata Journal (2003) 3, Number 3, pp. 302 308 From the help desk: Swamy s random-coefficients model Brian P. Poi Stata Corporation Abstract. This article discusses the Swamy (1970) random-coefficients

More information

Stata Tutorial. 1 Introduction. 1.1 Stata Windows and toolbar. Econometrics676, Spring2008

Stata Tutorial. 1 Introduction. 1.1 Stata Windows and toolbar. Econometrics676, Spring2008 1 Introduction Stata Tutorial Econometrics676, Spring2008 1.1 Stata Windows and toolbar Review : past commands appear here Variables : variables list Command : where you type your commands Results : results

More information

ECONOMICS 351* -- Stata 10 Tutorial 2. Stata 10 Tutorial 2

ECONOMICS 351* -- Stata 10 Tutorial 2. Stata 10 Tutorial 2 Stata 10 Tutorial 2 TOPIC: Introduction to Selected Stata Commands DATA: auto1.dta (the Stata-format data file you created in Stata Tutorial 1) or auto1.raw (the original text-format data file) TASKS:

More information

EXCEL Tutorial: How to use EXCEL for Graphs and Calculations.

EXCEL Tutorial: How to use EXCEL for Graphs and Calculations. EXCEL Tutorial: How to use EXCEL for Graphs and Calculations. Excel is powerful tool and can make your life easier if you are proficient in using it. You will need to use Excel to complete most of your

More information

Wooldridge, Introductory Econometrics, 3d ed. Chapter 12: Serial correlation and heteroskedasticity in time series regressions

Wooldridge, Introductory Econometrics, 3d ed. Chapter 12: Serial correlation and heteroskedasticity in time series regressions Wooldridge, Introductory Econometrics, 3d ed. Chapter 12: Serial correlation and heteroskedasticity in time series regressions What will happen if we violate the assumption that the errors are not serially

More information

Practical. I conometrics. data collection, analysis, and application. Christiana E. Hilmer. Michael J. Hilmer San Diego State University

Practical. I conometrics. data collection, analysis, and application. Christiana E. Hilmer. Michael J. Hilmer San Diego State University Practical I conometrics data collection, analysis, and application Christiana E. Hilmer Michael J. Hilmer San Diego State University Mi Table of Contents PART ONE THE BASICS 1 Chapter 1 An Introduction

More information

Factor Analysis. Chapter 420. Introduction

Factor Analysis. Chapter 420. Introduction Chapter 420 Introduction (FA) is an exploratory technique applied to a set of observed variables that seeks to find underlying factors (subsets of variables) from which the observed variables were generated.

More information

Least Squares Estimation

Least Squares Estimation Least Squares Estimation SARA A VAN DE GEER Volume 2, pp 1041 1045 in Encyclopedia of Statistics in Behavioral Science ISBN-13: 978-0-470-86080-9 ISBN-10: 0-470-86080-4 Editors Brian S Everitt & David

More information

IBM SPSS Direct Marketing 23

IBM SPSS Direct Marketing 23 IBM SPSS Direct Marketing 23 Note Before using this information and the product it supports, read the information in Notices on page 25. Product Information This edition applies to version 23, release

More information

HLM software has been one of the leading statistical packages for hierarchical

HLM software has been one of the leading statistical packages for hierarchical Introductory Guide to HLM With HLM 7 Software 3 G. David Garson HLM software has been one of the leading statistical packages for hierarchical linear modeling due to the pioneering work of Stephen Raudenbush

More information

Once saved, if the file was zipped you will need to unzip it. For the files that I will be posting you need to change the preferences.

Once saved, if the file was zipped you will need to unzip it. For the files that I will be posting you need to change the preferences. 1 Commands in JMP and Statcrunch Below are a set of commands in JMP and Statcrunch which facilitate a basic statistical analysis. The first part concerns commands in JMP, the second part is for analysis

More information

Figure 1. An embedded chart on a worksheet.

Figure 1. An embedded chart on a worksheet. 8. Excel Charts and Analysis ToolPak Charts, also known as graphs, have been an integral part of spreadsheets since the early days of Lotus 1-2-3. Charting features have improved significantly over the

More information

Using Excel for Statistics Tips and Warnings

Using Excel for Statistics Tips and Warnings Using Excel for Statistics Tips and Warnings November 2000 University of Reading Statistical Services Centre Biometrics Advisory and Support Service to DFID Contents 1. Introduction 3 1.1 Data Entry and

More information

Bowerman, O'Connell, Aitken Schermer, & Adcock, Business Statistics in Practice, Canadian edition

Bowerman, O'Connell, Aitken Schermer, & Adcock, Business Statistics in Practice, Canadian edition Bowerman, O'Connell, Aitken Schermer, & Adcock, Business Statistics in Practice, Canadian edition Online Learning Centre Technology Step-by-Step - Excel Microsoft Excel is a spreadsheet software application

More information

SAS Software to Fit the Generalized Linear Model

SAS Software to Fit the Generalized Linear Model SAS Software to Fit the Generalized Linear Model Gordon Johnston, SAS Institute Inc., Cary, NC Abstract In recent years, the class of generalized linear models has gained popularity as a statistical modeling

More information

IBM SPSS Direct Marketing 22

IBM SPSS Direct Marketing 22 IBM SPSS Direct Marketing 22 Note Before using this information and the product it supports, read the information in Notices on page 25. Product Information This edition applies to version 22, release

More information

7 Time series analysis

7 Time series analysis 7 Time series analysis In Chapters 16, 17, 33 36 in Zuur, Ieno and Smith (2007), various time series techniques are discussed. Applying these methods in Brodgar is straightforward, and most choices are

More information

A Short Guide to R with RStudio

A Short Guide to R with RStudio Short Guides to Microeconometrics Fall 2013 Prof. Dr. Kurt Schmidheiny Universität Basel A Short Guide to R with RStudio 1 Introduction 2 2 Installing R and RStudio 2 3 The RStudio Environment 2 4 Additions

More information

Chapter 4: Vector Autoregressive Models

Chapter 4: Vector Autoregressive Models Chapter 4: Vector Autoregressive Models 1 Contents: Lehrstuhl für Department Empirische of Wirtschaftsforschung Empirical Research and und Econometrics Ökonometrie IV.1 Vector Autoregressive Models (VAR)...

More information

Multivariate Analysis of Variance (MANOVA)

Multivariate Analysis of Variance (MANOVA) Chapter 415 Multivariate Analysis of Variance (MANOVA) Introduction Multivariate analysis of variance (MANOVA) is an extension of common analysis of variance (ANOVA). In ANOVA, differences among various

More information

A Primer on Mathematical Statistics and Univariate Distributions; The Normal Distribution; The GLM with the Normal Distribution

A Primer on Mathematical Statistics and Univariate Distributions; The Normal Distribution; The GLM with the Normal Distribution A Primer on Mathematical Statistics and Univariate Distributions; The Normal Distribution; The GLM with the Normal Distribution PSYC 943 (930): Fundamentals of Multivariate Modeling Lecture 4: September

More information

Data Analysis in SPSS. February 21, 2004. If you wish to cite the contents of this document, the APA reference for them would be

Data Analysis in SPSS. February 21, 2004. If you wish to cite the contents of this document, the APA reference for them would be Data Analysis in SPSS Jamie DeCoster Department of Psychology University of Alabama 348 Gordon Palmer Hall Box 870348 Tuscaloosa, AL 35487-0348 Heather Claypool Department of Psychology Miami University

More information

Exercise 1.12 (Pg. 22-23)

Exercise 1.12 (Pg. 22-23) Individuals: The objects that are described by a set of data. They may be people, animals, things, etc. (Also referred to as Cases or Records) Variables: The characteristics recorded about each individual.

More information

Standard errors of marginal effects in the heteroskedastic probit model

Standard errors of marginal effects in the heteroskedastic probit model Standard errors of marginal effects in the heteroskedastic probit model Thomas Cornelißen Discussion Paper No. 320 August 2005 ISSN: 0949 9962 Abstract In non-linear regression models, such as the heteroskedastic

More information

Interaction effects and group comparisons Richard Williams, University of Notre Dame, http://www3.nd.edu/~rwilliam/ Last revised February 20, 2015

Interaction effects and group comparisons Richard Williams, University of Notre Dame, http://www3.nd.edu/~rwilliam/ Last revised February 20, 2015 Interaction effects and group comparisons Richard Williams, University of Notre Dame, http://www3.nd.edu/~rwilliam/ Last revised February 20, 2015 Note: This handout assumes you understand factor variables,

More information

11. Analysis of Case-control Studies Logistic Regression

11. Analysis of Case-control Studies Logistic Regression Research methods II 113 11. Analysis of Case-control Studies Logistic Regression This chapter builds upon and further develops the concepts and strategies described in Ch.6 of Mother and Child Health:

More information

Data analysis and regression in Stata

Data analysis and regression in Stata Data analysis and regression in Stata This handout shows how the weekly beer sales series might be analyzed with Stata (the software package now used for teaching stats at Kellogg), for purposes of comparing

More information

Module 3: Correlation and Covariance

Module 3: Correlation and Covariance Using Statistical Data to Make Decisions Module 3: Correlation and Covariance Tom Ilvento Dr. Mugdim Pašiƒ University of Delaware Sarajevo Graduate School of Business O ften our interest in data analysis

More information

Using Excel (Microsoft Office 2007 Version) for Graphical Analysis of Data

Using Excel (Microsoft Office 2007 Version) for Graphical Analysis of Data Using Excel (Microsoft Office 2007 Version) for Graphical Analysis of Data Introduction In several upcoming labs, a primary goal will be to determine the mathematical relationship between two variable

More information

4. Descriptive Statistics: Measures of Variability and Central Tendency

4. Descriptive Statistics: Measures of Variability and Central Tendency 4. Descriptive Statistics: Measures of Variability and Central Tendency Objectives Calculate descriptive for continuous and categorical data Edit output tables Although measures of central tendency and

More information

XPost: Excel Workbooks for the Post-estimation Interpretation of Regression Models for Categorical Dependent Variables

XPost: Excel Workbooks for the Post-estimation Interpretation of Regression Models for Categorical Dependent Variables XPost: Excel Workbooks for the Post-estimation Interpretation of Regression Models for Categorical Dependent Variables Contents Simon Cheng hscheng@indiana.edu php.indiana.edu/~hscheng/ J. Scott Long jslong@indiana.edu

More information

Online Appendices to the Corporate Propensity to Save

Online Appendices to the Corporate Propensity to Save Online Appendices to the Corporate Propensity to Save Appendix A: Monte Carlo Experiments In order to allay skepticism of empirical results that have been produced by unusual estimators on fairly small

More information

2. Linear regression with multiple regressors

2. Linear regression with multiple regressors 2. Linear regression with multiple regressors Aim of this section: Introduction of the multiple regression model OLS estimation in multiple regression Measures-of-fit in multiple regression Assumptions

More information

IBM SPSS Missing Values 22

IBM SPSS Missing Values 22 IBM SPSS Missing Values 22 Note Before using this information and the product it supports, read the information in Notices on page 23. Product Information This edition applies to version 22, release 0,

More information

Data Analysis. Using Excel. Jeffrey L. Rummel. BBA Seminar. Data in Excel. Excel Calculations of Descriptive Statistics. Single Variable Graphs

Data Analysis. Using Excel. Jeffrey L. Rummel. BBA Seminar. Data in Excel. Excel Calculations of Descriptive Statistics. Single Variable Graphs Using Excel Jeffrey L. Rummel Emory University Goizueta Business School BBA Seminar Jeffrey L. Rummel BBA Seminar 1 / 54 Excel Calculations of Descriptive Statistics Single Variable Graphs Relationships

More information

1 Short Introduction to Time Series

1 Short Introduction to Time Series ECONOMICS 7344, Spring 202 Bent E. Sørensen January 24, 202 Short Introduction to Time Series A time series is a collection of stochastic variables x,.., x t,.., x T indexed by an integer value t. The

More information

0 Introduction to Data Analysis Using an Excel Spreadsheet

0 Introduction to Data Analysis Using an Excel Spreadsheet Experiment 0 Introduction to Data Analysis Using an Excel Spreadsheet I. Purpose The purpose of this introductory lab is to teach you a few basic things about how to use an EXCEL 2010 spreadsheet to do

More information

Statistics Review PSY379

Statistics Review PSY379 Statistics Review PSY379 Basic concepts Measurement scales Populations vs. samples Continuous vs. discrete variable Independent vs. dependent variable Descriptive vs. inferential stats Common analyses

More information

Microsoft Excel Tutorial

Microsoft Excel Tutorial Microsoft Excel Tutorial by Dr. James E. Parks Department of Physics and Astronomy 401 Nielsen Physics Building The University of Tennessee Knoxville, Tennessee 37996-1200 Copyright August, 2000 by James

More information

Performing Unit Root Tests in EViews. Unit Root Testing

Performing Unit Root Tests in EViews. Unit Root Testing Página 1 de 12 Unit Root Testing The theory behind ARMA estimation is based on stationary time series. A series is said to be (weakly or covariance) stationary if the mean and autocovariances of the series

More information

Module 2 Basic Data Management, Graphs, and Log-Files

Module 2 Basic Data Management, Graphs, and Log-Files AGRODEP Stata Training April 2013 Module 2 Basic Data Management, Graphs, and Log-Files Manuel Barron 1 and Pia Basurto 2 1 University of California, Berkeley, Department of Agricultural and Resource Economics

More information

STATGRAPHICS Online. Statistical Analysis and Data Visualization System. Revised 6/21/2012. Copyright 2012 by StatPoint Technologies, Inc.

STATGRAPHICS Online. Statistical Analysis and Data Visualization System. Revised 6/21/2012. Copyright 2012 by StatPoint Technologies, Inc. STATGRAPHICS Online Statistical Analysis and Data Visualization System Revised 6/21/2012 Copyright 2012 by StatPoint Technologies, Inc. All rights reserved. Table of Contents Introduction... 1 Chapter

More information

HYPOTHESIS TESTING: CONFIDENCE INTERVALS, T-TESTS, ANOVAS, AND REGRESSION

HYPOTHESIS TESTING: CONFIDENCE INTERVALS, T-TESTS, ANOVAS, AND REGRESSION HYPOTHESIS TESTING: CONFIDENCE INTERVALS, T-TESTS, ANOVAS, AND REGRESSION HOD 2990 10 November 2010 Lecture Background This is a lightning speed summary of introductory statistical methods for senior undergraduate

More information

UNDERSTANDING THE TWO-WAY ANOVA

UNDERSTANDING THE TWO-WAY ANOVA UNDERSTANDING THE e have seen how the one-way ANOVA can be used to compare two or more sample means in studies involving a single independent variable. This can be extended to two independent variables

More information

Introduction to Quantitative Methods

Introduction to Quantitative Methods Introduction to Quantitative Methods October 15, 2009 Contents 1 Definition of Key Terms 2 2 Descriptive Statistics 3 2.1 Frequency Tables......................... 4 2.2 Measures of Central Tendencies.................

More information

Intro to Excel spreadsheets

Intro to Excel spreadsheets Intro to Excel spreadsheets What are the objectives of this document? The objectives of document are: 1. Familiarize you with what a spreadsheet is, how it works, and what its capabilities are; 2. Using

More information

Scatter Plots with Error Bars

Scatter Plots with Error Bars Chapter 165 Scatter Plots with Error Bars Introduction The procedure extends the capability of the basic scatter plot by allowing you to plot the variability in Y and X corresponding to each point. Each

More information

Getting Correct Results from PROC REG

Getting Correct Results from PROC REG Getting Correct Results from PROC REG Nathaniel Derby, Statis Pro Data Analytics, Seattle, WA ABSTRACT PROC REG, SAS s implementation of linear regression, is often used to fit a line without checking

More information

Data analysis process

Data analysis process Data analysis process Data collection and preparation Collect data Prepare codebook Set up structure of data Enter data Screen data for errors Exploration of data Descriptive Statistics Graphs Analysis

More information

STATISTICA Formula Guide: Logistic Regression. Table of Contents

STATISTICA Formula Guide: Logistic Regression. Table of Contents : Table of Contents... 1 Overview of Model... 1 Dispersion... 2 Parameterization... 3 Sigma-Restricted Model... 3 Overparameterized Model... 4 Reference Coding... 4 Model Summary (Summary Tab)... 5 Summary

More information

A Short Guide to Stata 13

A Short Guide to Stata 13 Short Guides to Microeconometrics Fall 2015 Prof. Dr. Kurt Schmidheiny Universität Basel A Short Guide to Stata 13 1 Introduction 2 2 The Stata Environment 2 3 Where to get help 3 4 Additions to Stata

More information

4 Other useful features on the course web page. 5 Accessing SAS

4 Other useful features on the course web page. 5 Accessing SAS 1 Using SAS outside of ITCs Statistical Methods and Computing, 22S:30/105 Instructor: Cowles Lab 1 Jan 31, 2014 You can access SAS from off campus by using the ITC Virtual Desktop Go to https://virtualdesktopuiowaedu

More information

Marginal Effects for Continuous Variables Richard Williams, University of Notre Dame, http://www3.nd.edu/~rwilliam/ Last revised February 21, 2015

Marginal Effects for Continuous Variables Richard Williams, University of Notre Dame, http://www3.nd.edu/~rwilliam/ Last revised February 21, 2015 Marginal Effects for Continuous Variables Richard Williams, University of Notre Dame, http://www3.nd.edu/~rwilliam/ Last revised February 21, 2015 References: Long 1997, Long and Freese 2003 & 2006 & 2014,

More information

SPSS: Getting Started. For Windows

SPSS: Getting Started. For Windows For Windows Updated: August 2012 Table of Contents Section 1: Overview... 3 1.1 Introduction to SPSS Tutorials... 3 1.2 Introduction to SPSS... 3 1.3 Overview of SPSS for Windows... 3 Section 2: Entering

More information

Chapter 1. Vector autoregressions. 1.1 VARs and the identi cation problem

Chapter 1. Vector autoregressions. 1.1 VARs and the identi cation problem Chapter Vector autoregressions We begin by taking a look at the data of macroeconomics. A way to summarize the dynamics of macroeconomic data is to make use of vector autoregressions. VAR models have become

More information

Chapter 7: Simple linear regression Learning Objectives

Chapter 7: Simple linear regression Learning Objectives Chapter 7: Simple linear regression Learning Objectives Reading: Section 7.1 of OpenIntro Statistics Video: Correlation vs. causation, YouTube (2:19) Video: Intro to Linear Regression, YouTube (5:18) -

More information

How to set the main menu of STATA to default factory settings standards

How to set the main menu of STATA to default factory settings standards University of Pretoria Data analysis for evaluation studies Examples in STATA version 11 List of data sets b1.dta (To be created by students in class) fp1.xls (To be provided to students) fp1.txt (To be

More information

IBM SPSS Statistics 20 Part 4: Chi-Square and ANOVA

IBM SPSS Statistics 20 Part 4: Chi-Square and ANOVA CALIFORNIA STATE UNIVERSITY, LOS ANGELES INFORMATION TECHNOLOGY SERVICES IBM SPSS Statistics 20 Part 4: Chi-Square and ANOVA Summer 2013, Version 2.0 Table of Contents Introduction...2 Downloading the

More information

Microsoft Excel Tutorial

Microsoft Excel Tutorial Microsoft Excel Tutorial Microsoft Excel spreadsheets are a powerful and easy to use tool to record, plot and analyze experimental data. Excel is commonly used by engineers to tackle sophisticated computations

More information

How To Check For Differences In The One Way Anova

How To Check For Differences In The One Way Anova MINITAB ASSISTANT WHITE PAPER This paper explains the research conducted by Minitab statisticians to develop the methods and data checks used in the Assistant in Minitab 17 Statistical Software. One-Way

More information

MULTIPLE REGRESSION EXAMPLE

MULTIPLE REGRESSION EXAMPLE MULTIPLE REGRESSION EXAMPLE For a sample of n = 166 college students, the following variables were measured: Y = height X 1 = mother s height ( momheight ) X 2 = father s height ( dadheight ) X 3 = 1 if

More information

Predictor Coef StDev T P Constant 970667056 616256122 1.58 0.154 X 0.00293 0.06163 0.05 0.963. S = 0.5597 R-Sq = 0.0% R-Sq(adj) = 0.

Predictor Coef StDev T P Constant 970667056 616256122 1.58 0.154 X 0.00293 0.06163 0.05 0.963. S = 0.5597 R-Sq = 0.0% R-Sq(adj) = 0. Statistical analysis using Microsoft Excel Microsoft Excel spreadsheets have become somewhat of a standard for data storage, at least for smaller data sets. This, along with the program often being packaged

More information

Bill Burton Albert Einstein College of Medicine william.burton@einstein.yu.edu April 28, 2014 EERS: Managing the Tension Between Rigor and Resources 1

Bill Burton Albert Einstein College of Medicine william.burton@einstein.yu.edu April 28, 2014 EERS: Managing the Tension Between Rigor and Resources 1 Bill Burton Albert Einstein College of Medicine william.burton@einstein.yu.edu April 28, 2014 EERS: Managing the Tension Between Rigor and Resources 1 Calculate counts, means, and standard deviations Produce

More information

Institute of Actuaries of India Subject CT3 Probability and Mathematical Statistics

Institute of Actuaries of India Subject CT3 Probability and Mathematical Statistics Institute of Actuaries of India Subject CT3 Probability and Mathematical Statistics For 2015 Examinations Aim The aim of the Probability and Mathematical Statistics subject is to provide a grounding in

More information

IBM SPSS Data Preparation 22

IBM SPSS Data Preparation 22 IBM SPSS Data Preparation 22 Note Before using this information and the product it supports, read the information in Notices on page 33. Product Information This edition applies to version 22, release

More information

Syntax Menu Description Options Remarks and examples Stored results Methods and formulas References Also see. Description

Syntax Menu Description Options Remarks and examples Stored results Methods and formulas References Also see. Description Title stata.com lpoly Kernel-weighted local polynomial smoothing Syntax Menu Description Options Remarks and examples Stored results Methods and formulas References Also see Syntax lpoly yvar xvar [ if

More information

Engineering Problem Solving and Excel. EGN 1006 Introduction to Engineering

Engineering Problem Solving and Excel. EGN 1006 Introduction to Engineering Engineering Problem Solving and Excel EGN 1006 Introduction to Engineering Mathematical Solution Procedures Commonly Used in Engineering Analysis Data Analysis Techniques (Statistics) Curve Fitting techniques

More information

PITFALLS IN TIME SERIES ANALYSIS. Cliff Hurvich Stern School, NYU

PITFALLS IN TIME SERIES ANALYSIS. Cliff Hurvich Stern School, NYU PITFALLS IN TIME SERIES ANALYSIS Cliff Hurvich Stern School, NYU The t -Test If x 1,..., x n are independent and identically distributed with mean 0, and n is not too small, then t = x 0 s n has a standard

More information

Spreadsheets and Laboratory Data Analysis: Excel 2003 Version (Excel 2007 is only slightly different)

Spreadsheets and Laboratory Data Analysis: Excel 2003 Version (Excel 2007 is only slightly different) Spreadsheets and Laboratory Data Analysis: Excel 2003 Version (Excel 2007 is only slightly different) Spreadsheets are computer programs that allow the user to enter and manipulate numbers. They are capable

More information

MULTIPLE LINEAR REGRESSION ANALYSIS USING MICROSOFT EXCEL. by Michael L. Orlov Chemistry Department, Oregon State University (1996)

MULTIPLE LINEAR REGRESSION ANALYSIS USING MICROSOFT EXCEL. by Michael L. Orlov Chemistry Department, Oregon State University (1996) MULTIPLE LINEAR REGRESSION ANALYSIS USING MICROSOFT EXCEL by Michael L. Orlov Chemistry Department, Oregon State University (1996) INTRODUCTION In modern science, regression analysis is a necessary part

More information

Tutorial: Get Running with Amos Graphics

Tutorial: Get Running with Amos Graphics Tutorial: Get Running with Amos Graphics Purpose Remember your first statistics class when you sweated through memorizing formulas and laboriously calculating answers with pencil and paper? The professor

More information

Regression Clustering

Regression Clustering Chapter 449 Introduction This algorithm provides for clustering in the multiple regression setting in which you have a dependent variable Y and one or more independent variables, the X s. The algorithm

More information