Econometric Problems Lab Metrics Lab Import Data and
Econometric Problems Lab Metrics Lab
Import Data and Run Basic Regression �Import the Macro data from Excel and use first row as variable names �Time set the year variable by typing “tsset year” into the command window. �STATA now knows that is a time series data allowing operators such as lag and lead to work �Run a basic OLS regression using personal consumption as the dependent variable. �“regress personalconsumption gdp disposableincome unemploymentrate year”
STATA-Generating Residuals �To generate the residuals in stata type the command: “predict resid, r” � This tells STATA that you are generating a new variable, naming it resid, and you want it to equal the error terms from the model. �Your residuals will appear in your data editor
STATA-Generating Fitted Values �To generate the fitted values, type: “predict yhat, xb” � This tells STATA that you want to generate a new variable named yhat where it equals the predicted values of the model. �Your fitted values will appear in your data editor
Plotting Residuals and Fitted Values �To plot your residuals against your fitted values type “scatter yhat resid” � You may also use “plot yhat resid” to have you results appear in the results window. �In a new window, you’ll see the scatter plot.
Residuals Vs. Predicted Values
Regress with Squared Residuals
Heteroskedasticity �Heteroskedasticity occurs when the error variance has non-constant variance. �Error variance definition: the portion of the variance in a set of scores that is due to extraneous variables and measurement error. �Can someone explain me the difference between errors and residuals? �The variance of the observed value of the dependent variable around the regression line is non-constant.
Difference between Errors and Residuals �The error (or disturbance) of an observed value is the deviation of the observed value from the (unobservable) true value of a quantity of interest (for example, a population mean) �Ex. The difference between the height of each man in the sample and the unobservable population mean �The residual of an observed value is the difference between the observed value and the estimated value of the quantity of interest (for example, a sample mean). �Ex. The difference between the height of each man in the sample and the observable sample mean
STATA-Detecting Heteroskedasticity �To determine if you have heteroskedasticity you’ll want to run either a White test or the Breusch-Pagan/Cook. Weisberg test for heteroskedasticity. �To run the Breusch. Pagan test, type “estat hettest” directly after running your regression. Compare the chisquare statistic to a table. The high p-value indicates that heteroskedasticity is not a problem here.
Breusch-Pagan/Cook-Weisberg Test �It tests whether the estimated variance of the residuals from a regression are dependent on the values of the independent variables. In that case, heteroskedasticity is present. �The Breusch–Pagan tests for conditional heteroskedasticity. It is a chi-squared test: the test statistic is nχ2 with k degrees of freedom. It tests the null hypothesis of homoskedasticity. If the Chi Squared value is significant with p-value below an appropriate threshold (e. g. p<0. 05) then the null hypothesis of homoskedasticity is rejected and heteroskedasticity assumed. �If the errors have constant variance, the errors are called homoscedastic
White Test �To conduct a white test, type “imtest, white” directly following your regression.
White Test � It’s similar to the Breusch-Pagan test, but the White test allows the independent variable to have a nonlinear and interactive effect on the error variance. Skewness Kurtosis
STATA-Detecting Skewness �To determine non-normality of error terms, or skewness, you want to run a JB test. �The command for the skewness test is “sktest resid” � where resid is the name of your residuals If the number is bigger than 5. 99 (Chi-square with 2 df at the 5 % level) your error terms are not normally distributed and you have a problem.
JB test continued �Alternatively you can install the JB test into stata using the command: “ssc install jb” �After installation you can run the jb test using the command: �“jb res” where res is the name of the variable with the residual values from your regression
Plotting Residuals �You may also wish to see a histogram of the residuals. �Command: “histogram resid” –the histogram will appear in a new window.
STATA-Detecting Multicollinearity �To detect multicollinearity in STATA you will want to create a correlation matrix. �Command: “Correl varlist” rho’s of o. 5 or greater should give you concern.
STATA-Detecting Autocorrelation � To detect autocorrelation, you will want to run a Durbin- Watson test. � Command: “estat dwatson” (remember that you must have time-set your data to run a durbin watson test— tsset Var. Name) � Or “dwstat” after you have generated a time variable and set it as a time series—”gen time = _n” ”tsset time” Compare the d-statistic to a durbin-watson table in order to determine your dl and du (I’ve included a table on the next slide)
Durbin-Watson Table (α=0. 05)
Two-tailed test �If d<d. L or d>4 -d. L treat as a problem (RED) �If d. L<d<d. U or 4 -d. U<d<4 -d. L then inconclusive (YELLOW) �If d. U<d<4 -d. U treat as no problem (GREEN) ? + exists 0 20 d. L No + d. U ? No - 2 4 -d. U - exists 4 -d. L 4
Newey-West �To run your regression with Newey corrected SE: Command: Newey dependvar independvars, lag(#)
Questions? Stop by the lab or email with questions
- Slides: 22