Example: air traffic controller

Linear Regression using Stata - princeton.edu

Linear Regression using Stata ( ). Oscar Torres-Reyna December 2007 Regression : a practical approach (overview). We use Regression to estimate the unknown effect of changing one variable over another (Stock and Watson, 2003, ch. 4). When running a Regression we are making two assumptions, 1) there is a Linear relationship between two variables ( X and Y) and 2) this relationship is additive ( Y= x1 + x2 + +xN). Technically, Linear Regression estimates how much Y changes when X changes one unit. In Stata use the command regress, type: regress [dependent variable] [independent variable(s)]. regress y x In a multivariate setting we type: regress y x1 x2 x3 . Before running a Regression it is recommended to have a clear idea of what you are trying to estimate ( which are your outcome and predictor variables). A Regression makes sense only if there is a sound theory behind it.

PU/DSS/OTR Regression: a practical approach (overview) We use regression to estimate the unknown effectof changing one variable over another (Stock and Watson, 2003, ch. 4)

Tags:

  Princeton

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Linear Regression using Stata - princeton.edu

1 Linear Regression using Stata ( ). Oscar Torres-Reyna December 2007 Regression : a practical approach (overview). We use Regression to estimate the unknown effect of changing one variable over another (Stock and Watson, 2003, ch. 4). When running a Regression we are making two assumptions, 1) there is a Linear relationship between two variables ( X and Y) and 2) this relationship is additive ( Y= x1 + x2 + +xN). Technically, Linear Regression estimates how much Y changes when X changes one unit. In Stata use the command regress, type: regress [dependent variable] [independent variable(s)]. regress y x In a multivariate setting we type: regress y x1 x2 x3 . Before running a Regression it is recommended to have a clear idea of what you are trying to estimate ( which are your outcome and predictor variables). A Regression makes sense only if there is a sound theory behind it.

2 2. PU/DSS/OTR. Regression : a practical approach (setting). Example: Are SAT scores higher in states that spend more money on education controlling by other factors?*. Outcome (Y) variable SAT scores, variable csat in dataset Predictor (X) variables Per pupil expenditures primary & secondary (expense). % HS graduates taking SAT (percent). Median household income (income). % adults with HS diploma (high). % adults with college degree (college). Region (region). *Source: Data and examples come from the book Statistics with Stata (updated for version 9) by Lawrence C. Hamilton (chapter 6). Click here to download the data or search for it at 3. Use the file (educational data for the ). PU/DSS/OTR. Regression : variables It is recommended first to examine the variables in the model to check for possible errors, type: use describe csat expense percent income high college region summarize csat expense percent income high college region.

3 Describe csat expense percent income high college region storage display value variable name type format label variable label csat int % Mean composite SAT score expense int % Per pup il expenditures prim&sec percent byte % % HS graduates taking SAT. income double % Median household income, $1,000. high float % % adults HS diploma college float % % adults college degree region byte % region Geographical region . summarize csat expense percent income high college region Variable Obs Mean Std. Dev. Min Max csat 51 832 1093. expense 51 2960 9259. percent 51 4 81. income 51 high 51 college 51 region 50 1 4. 4. PU/DSS/OTR. Regression : what to look for Lets run the Regression : regress csat expense, robust This is the p-value of the model. It Outcome Predictor Robust standard errors (to control 1. for heteroskedasticity) tests whether R2 is different from variable (Y) variable (X) 0.

4 Usually we need a p-value lower than to show a statistically significant relationship . regress csat expense, robust between X and Y. Linear Regression Number of obs = 51 2 R-square shows the amount of F( 1, 49) = Prob > F = variance of Y explained by X. In Root MSE: root mean squared error, is the sd of the R-squared = this case expense explains 22%. 7 Root MSE = of the variance in SAT scores. Regression . The closer to zero better the fit. Robust csat Coef. Std. Err. t P>|t| [95% Conf. Interval] Adj R2 (not shown here) shows expense .0036719 the same as R2 but adjusted by _cons the # of cases and # of variables. When the # of variables is small 6 3. and the # of cases is very large then Adj R2 is closer to R2. This csat = 1061 - *expense provides a more honest For each one-point increase in expense, SAT association between X and Y. scores decrease by points.

5 4. 5. Two-tail p-values test the hypothesis that each coefficient is different The t-values test the hypothesis that the coefficient is from 0. To reject this, the p-value has to be lower than (you different from 0. To reject this, you need a t-value greater could choose also an alpha of ). In this case, expense is than (for 95% confidence). You can get the t-values statistically significant in explaining SAT. by dividing the coefficient by its standard error. The t- values also show the importance of a variable in the 5. model. PU/DSS/OTR. Regression : what to look for Robust standard errors (to control Adding the rest of predictor variables: for heteroskedasticity). regress csat expense percent income high college, robust This is the p-value of the model. It Output variable (Y) Predictor variables (X) 1. indicates the reliability of X to predict Y.

6 Usually we need a p- value lower than to show a . regress csat expense percent income high college, robust statistically significant relationship Linear Regression Number of obs = 51 between X and Y. F( 5, 45) = Prob > F = 2. R-squared = R-square shows the amount of Root MSE: root mean squared error, is the sd of the Root MSE = 7 variance of Y explained by X. In Regression . The closer to zero better the fit. this case the model explains Robust of the variance in SAT. csat Coef. Std. Err. t P>|t| [95% Conf. Interval] scores. expense .0033528 .004781 .0129823. percent .2288594 Adj R2 (not shown here) shows income .1055853 the same as R2 but adjusted by high .943318 college the # of cases and # of variables. _cons When the # of variables is small 3. and the # of cases is very large then Adj R2 is closer to R2. This 6. provides a more honest csat = + *expense association between X and Y.

7 4. *percent + *income + *high 5. + *college Two-tail p-values test the hypothesis that each coefficient is different The t-values test the hypothesis that the coefficient is from 0. To reject this, the p-value has to be lower than (you different from 0. To reject this, you need a t-value greater could choose also an alpha of ). In this case, expense, than (at confidence). You can get the t-values income, and college are not statistically significant in explaining by dividing the coefficient by its standard error. The t- SAT; high is almost significant at Percent is the only variable values also show the importance of a variable in the that has some significant impact on SAT (its coefficient is different 6. model. In this case, percent is the most important. from 0). PU/DSS/OTR. Regression : using dummy variables/selecting the reference category If using categorical variables in your Regression , you need to add n-1 dummy variables.

8 Here n' is the number of categories in the variable. In the example below, variable industry' has twelve categories (type tab industry, or tab industry, nolabel). The easiest way to include a set of dummies in a Regression is by To change the reference category to Professional services . using the prefix i. By default, the first category (or lowest value) is (category number 11) instead of Ag/Forestry/Fisheries (category used as reference. For example: number 1), use the prefix ib#. where # is the number of the reference category you want to use; in this case is 11. sysuse reg wage hours , robust sysuse reg wage hours , robust Linear Regression Number of obs = 2228. F( 12, 2215) = Linear Regression Number of obs = 2228. F( 12, 2215) = Prob > F = Prob > F = R-squared = R-squared = Root MSE = Root MSE = Robust Robust wage Coef. Std. Err.

9 T P>|t| [95% Conf. Interval]. wage Coef. Std. Err. t P>|t| [95% Conf. Interval]. hours .0723658 .0110213 .0507526 .093979 hours .0723658 .0110213 .0507526 .093979. industry industry Mining Ag/Forestry/Fisheries .8192781 Construction Mining Manufacturing .849571 Construction Transport/Comm/Utility Manufacturing .3362365 Wholesale/Retail Trade .4583809 .8548564 Transport/Comm/Utility .6861828 Finance/Ins/Real Estate .9934195 Wholesale/Retail Trade .3504059 Business/Repair Svc Finance/Ins/Real Estate .6171526 .6240837 Personal Services .8439617 .6362679 Business/Repair Svc .7094241 Entertainment/Rec Svc Personal Services .3192289 Professional Services .8192781 .4883548 Entertainment/Rec Svc .9004471 .7826217. Public Administration .8857298 Public Administration .4176899 .3183117 _cons .8899074 _cons .4119032 The ib#. option is available since Stata 11 (type help fvvarlist for more options/details).

10 For older Stata versions you need to use xi: along with i. (type help xi for more options/details). For the examples above type (output omitted): xi: reg wage hours , robust char industry[omit]11 /* using category 11 as reference*/. xi: reg wage hours , robust To create dummies as variables type To include all categories by suppressing the constant type: tab industry, gen(industry) reg wage hours , robust hascons Regression : ANOVA table If you run the Regression without the robust' option you get the ANOVA table xi: regress csat expense percent income high college Source SS df MS Number of obs = 50. F( 9, 40) = Model (A) 9 (D) Prob > F = Residual (B) 40 (E) R-squared = Adj R-squared = Total (C) 49 (F) Root MSE = MSS (k 1) 9 D n 1 49 E F= = = = = AdjR 2 = 1 (1 R 2 ) = 1 (1 ) = 1 = 1 = RSS E n k 40 F n k 40. 2. R =. MSS. = 1 . ei = = A = 2.


Related search queries