Introductory Econometrics Using R

Example 2.3. CEO Salary & Return on Equity

Install/load necessary packages

#install.packages("wooldridge")
library(wooldridge)
#install.packages("psych")
library(psych)

Data description

options(width=150)
data(ceosal1)
describe(ceosal1)
##          vars   n    mean       sd  median trimmed     mad    min      max    range skew kurtosis     se
## salary      1 209 1281.12  1372.35 1039.00 1078.88  472.95 223.00 14822.00 14599.00 6.81    56.96  94.93
## pcsalary    2 209   13.28    32.63    9.00    9.39   14.83 -61.00   212.00   273.00 2.71    12.14   2.26
## sales       3 209 6923.79 10633.27 3705.20 4785.73 3077.73 175.20 97649.90 97474.70 4.96    31.96 735.52
## roe         4 209   17.18     8.52   15.50   16.21    5.78   0.50    56.30    55.80 1.55     3.61   0.59
## pcroe       5 209   10.80    97.22   -3.00   -1.84   28.61 -98.90   977.00  1075.90 6.37    52.56   6.72
## ros         6 209   61.80    68.18   52.00   52.46   44.48 -58.00   418.00   476.00 2.06     6.31   4.72
## indus       7 209    0.32     0.47    0.00    0.28    0.00   0.00     1.00     1.00 0.76    -1.42   0.03
## finance     8 209    0.22     0.42    0.00    0.15    0.00   0.00     1.00     1.00 1.34    -0.20   0.03
## consprod    9 209    0.29     0.45    0.00    0.24    0.00   0.00     1.00     1.00 0.93    -1.13   0.03
## utility    10 209    0.17     0.38    0.00    0.09    0.00   0.00     1.00     1.00 1.72     0.98   0.03
## lsalary    11 209    6.95     0.57    6.95    6.93    0.47   5.41     9.60     4.20 0.87     3.21   0.04
## lsales     12 209    8.29     1.01    8.22    8.28    0.87   5.17    11.49     6.32 0.09     0.72   0.07

Simple linear regression (OLS)

salary_eq <- lm( salary ~ roe, data=ceosal1 )
summary(salary_eq)
## 
## Call:
## lm(formula = salary ~ roe, data = ceosal1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1160.2  -526.0  -254.0   138.8 13499.9 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   963.19     213.24   4.517 1.05e-05 ***
## roe            18.50      11.12   1.663   0.0978 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1367 on 207 degrees of freedom
## Multiple R-squared:  0.01319,    Adjusted R-squared:  0.008421 
## F-statistic: 2.767 on 1 and 207 DF,  p-value: 0.09777

Example 2.4. Wage Equation

Average values

avg_salary <- mean(wage1$wage) 
avg_yrs_educ <- mean(wage1$educ)
cbind(avg_salary, avg_yrs_educ)
##      avg_salary avg_yrs_educ
## [1,]   5.896103     12.56274

Regression

wage_eq <- lm( wage ~ educ, data=wage1 )
summary(wage_eq)
## 
## Call:
## lm(formula = wage ~ educ, data = wage1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.3396 -2.1501 -0.9674  1.1921 16.6085 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.90485    0.68497  -1.321    0.187    
## educ         0.54136    0.05325  10.167   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.378 on 524 degrees of freedom
## Multiple R-squared:  0.1648, Adjusted R-squared:  0.1632 
## F-statistic: 103.4 on 1 and 524 DF,  p-value: < 2.2e-16

Example 2.5. Vote share

vote_ols = lm(voteA ~ shareA, data=vote1)
summary(vote_ols)
## 
## Call:
## lm(formula = voteA ~ shareA, data = vote1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -16.8919  -4.0660  -0.1682   3.4965  29.9772 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 26.81221    0.88721   30.22   <2e-16 ***
## shareA       0.46383    0.01454   31.90   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.385 on 171 degrees of freedom
## Multiple R-squared:  0.8561, Adjusted R-squared:  0.8553 
## F-statistic:  1018 on 1 and 171 DF,  p-value: < 2.2e-16

Example 2.6. Table 2.2

salary_ols = lm(salary ~ roe, data=ceosal1)
salary_hat <- fitted(salary_ols)
u_hat <- resid(salary_ols)
salary<-ceosal1$salary
roe<-ceosal1$roe
cbind(roe, salary, salary_hat, u_hat)[1:15,]
##     roe salary salary_hat       u_hat
## 1  14.1   1095   1224.058 -129.058071
## 2  10.9   1001   1164.854 -163.854261
## 3  23.5   1122   1397.969 -275.969216
## 4   5.9    578   1072.348 -494.348338
## 5  13.8   1368   1218.508  149.492288
## 6  20.0   1145   1333.215 -188.215063
## 7  16.4   1078   1266.611 -188.610785
## 8  16.3   1094   1264.761 -170.760660
## 9  10.5   1237   1157.454   79.546207
## 10 26.3    833   1449.773 -616.772523
## 11 25.9    567   1442.372 -875.372056
## 12 26.8    933   1459.023 -526.023116
## 13 14.8   1339   1237.009  101.991102
## 14 22.3    937   1375.768 -438.767778
## 15 56.3   2011   2004.808    6.191886

Example 2.7. Wage & education

wage_ols <- lm(wage ~ educ, data=wage1)
#install.packages("stargazer")
library(stargazer)
stargazer(wage_ols, type="text", title="Result", align=TRUE)
## 
## Result
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                                wage            
## -----------------------------------------------
## educ                         0.541***          
##                               (0.053)          
##                                                
## Constant                      -0.905           
##                               (0.685)          
##                                                
## -----------------------------------------------
## Observations                    526            
## R2                             0.165           
## Adjusted R2                    0.163           
## Residual Std. Error      3.378 (df = 524)      
## F Statistic          103.363*** (df = 1; 524)  
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
coefficients <- coef(wage_ols)
wage_hat <- coefficients[2]*mean(wage1$educ) + coefficients[1]
wage_hat
##     educ 
## 5.896103

Example 2.8. CEO Salary - R-squared

salary_ols <- lm(salary ~ 1 + roe, data=ceosal1)
stargazer(salary_ols, type="text", align=TRUE)
## 
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                               salary           
## -----------------------------------------------
## roe                           18.501*          
##                              (11.123)          
##                                                
## Constant                    963.191***         
##                              (213.240)         
##                                                
## -----------------------------------------------
## Observations                    209            
## R2                             0.013           
## Adjusted R2                    0.008           
## Residual Std. Error    1,366.555 (df = 207)    
## F Statistic            2.767* (df = 1; 207)    
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
1-var(resid(salary_ols))/var(ceosal1$salary)  #R-square 
## [1] 0.01318862
cor(ceosal1$salary, fitted(salary_ols))^2   #R-square
## [1] 0.01318862

Example2.9 Voting outcome - R-squared

vote_ols <- lm(voteA ~ shareA, data=vote1)
stargazer(vote_ols, type="text", align=TRUE)
## 
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                                voteA           
## -----------------------------------------------
## shareA                       0.464***          
##                               (0.015)          
##                                                
## Constant                     26.812***         
##                               (0.887)          
##                                                
## -----------------------------------------------
## Observations                    173            
## R2                             0.856           
## Adjusted R2                    0.855           
## Residual Std. Error      6.385 (df = 171)      
## F Statistic         1,017.663*** (df = 1; 171) 
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
var(fitted(vote_ols))/var(vote1$voteA) #R-square
## [1] 0.8561409

Example 2.3. in session 2.4: Units of measurement & functional form

sal1000 <- (ceosal1$salary)*1000
roe <- ceosal1$roe
sal1000_ols <- lm(sal1000 ~ roe)
salary_ols <- lm(salary ~ 1 + roe, data=ceosal1)
stargazer(salary_ols, sal1000_ols, type="text", title="Results", align=TRUE)
## 
## Results
## ===========================================================
##                                    Dependent variable:     
##                                ----------------------------
##                                   salary        sal1000    
##                                     (1)           (2)      
## -----------------------------------------------------------
## roe                               18.501*     18,501.190*  
##                                  (11.123)     (11,123.250) 
##                                                            
## Constant                        963.191***   963,191.300***
##                                  (213.240)   (213,240.300) 
##                                                            
## -----------------------------------------------------------
## Observations                        209           209      
## R2                                 0.013         0.013     
## Adjusted R2                        0.008         0.008     
## Residual Std. Error (df = 207)   1,366.555   1,366,555.000 
## F Statistic (df = 1; 207)         2.767*         2.767*    
## ===========================================================
## Note:                           *p<0.1; **p<0.05; ***p<0.01

Example 2.10. A log wage equation (log-lin model, semi-elasticity )

lwage_reg <- lm(lwage ~ 1 + educ, data=wage1)
stargazer(lwage_reg, type="text", align=TRUE) 
## 
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                                lwage           
## -----------------------------------------------
## educ                         0.083***          
##                               (0.008)          
##                                                
## Constant                     0.584***          
##                               (0.097)          
##                                                
## -----------------------------------------------
## Observations                    526            
## R2                             0.186           
## Adjusted R2                    0.184           
## Residual Std. Error      0.480 (df = 524)      
## F Statistic          119.582*** (df = 1; 524)  
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01

Example 2.11. Ceo Salary & Fim Sales (log-log model, elasticity)

lsalary_reg <- lm(lsalary ~ 1 + lsales, data=ceosal1)
stargazer(lsalary_reg, type="text", align=TRUE) 
## 
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                               lsalary          
## -----------------------------------------------
## lsales                       0.257***          
##                               (0.035)          
##                                                
## Constant                     4.822***          
##                               (0.288)          
##                                                
## -----------------------------------------------
## Observations                    209            
## R2                             0.211           
## Adjusted R2                    0.207           
## Residual Std. Error      0.504 (df = 207)      
## F Statistic           55.297*** (df = 1; 207)  
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01

Example 2.12 Student math performance

math_ols = lm(math10 ~ 1 + lnchprg, data=meap93)
stargazer(math_ols, type="text", align=TRUE)
## 
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                               math10           
## -----------------------------------------------
## lnchprg                      -0.319***         
##                               (0.035)          
##                                                
## Constant                     32.143***         
##                               (0.998)          
##                                                
## -----------------------------------------------
## Observations                    408            
## R2                             0.171           
## Adjusted R2                    0.169           
## Residual Std. Error      9.566 (df = 406)      
## F Statistic           83.767*** (df = 1; 406)  
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01