setwd("C:/Users/marcogeovanni/Desktop/Modern Guide To Econometrics/Chapter 3")
library("readstata13", lib.loc="~/R/win-library/3.2")
clothing <- read.dta13("clothing.dta")
summary(clothing)
##      tsales            sales           margin           nown       
##  Min.   :  50000   Min.   :  300   Min.   :16.00   Min.   : 1.000  
##  1st Qu.: 495340   1st Qu.: 3904   1st Qu.:37.00   1st Qu.: 1.000  
##  Median : 694227   Median : 5279   Median :39.00   Median : 1.000  
##  Mean   : 833584   Mean   : 6335   Mean   :38.77   Mean   : 1.284  
##  3rd Qu.: 976817   3rd Qu.: 7740   3rd Qu.:41.00   3rd Qu.: 1.295  
##  Max.   :5000000   Max.   :27000   Max.   :66.00   Max.   :10.000  
##      nfull           npart            naux           hoursw     
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   : 32.0  
##  1st Qu.:1.923   1st Qu.:1.283   1st Qu.:1.333   1st Qu.: 80.0  
##  Median :1.956   Median :1.283   Median :1.367   Median :104.0  
##  Mean   :2.069   Mean   :1.566   Mean   :1.390   Mean   :121.1  
##  3rd Qu.:2.066   3rd Qu.:2.000   3rd Qu.:1.367   3rd Qu.:145.2  
##  Max.   :8.000   Max.   :9.000   Max.   :4.000   Max.   :582.0  
##     hourspw            inv1              inv2            ssize       
##  Min.   : 5.708   Min.   :   1000   Min.   :   350   Min.   :  16.0  
##  1st Qu.:13.541   1st Qu.:  20000   1st Qu.: 10000   1st Qu.:  80.0  
##  Median :17.745   Median :  22207   Median : 22860   Median : 120.0  
##  Mean   :18.955   Mean   :  58257   Mean   : 27829   Mean   : 151.1  
##  3rd Qu.:24.303   3rd Qu.:  62269   3rd Qu.: 22860   3rd Qu.: 190.0  
##  Max.   :43.326   Max.   :1500000   Max.   :400000   Max.   :1214.0  
##      start      
##  Min.   :16.00  
##  1st Qu.:37.00  
##  Median :40.00  
##  Mean   :42.81  
##  3rd Qu.:42.00  
##  Max.   :90.00
attach(clothing)
hist(sales, col="red")

hist(hoursw, col="green")

hist(ssize, col="purple")

reg1<- lm(sales~hoursw + ssize)
summary(reg1)
## 
## Call:
## lm(formula = sales ~ hoursw + ssize)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5658.5 -1874.1  -466.8   937.6 18076.3 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 5133.590    321.693   15.96   <2e-16 ***
## hoursw        37.528      2.837   13.23   <2e-16 ***
## ssize        -22.145      1.625  -13.63   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2985 on 397 degrees of freedom
## Multiple R-squared:  0.3658, Adjusted R-squared:  0.3626 
## F-statistic: 114.5 on 2 and 397 DF,  p-value: < 2.2e-16
reg3 <-lm(sales~hoursw + ssize + nown + npart)
summary(reg3)
## 
## Call:
## lm(formula = sales ~ hoursw + ssize + nown + npart)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6424.2 -1869.8  -492.7  1079.3 18028.7 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 4494.511    462.795   9.712  < 2e-16 ***
## hoursw        39.024      3.094  12.611  < 2e-16 ***
## ssize        -24.324      1.694 -14.356  < 2e-16 ***
## nown        -385.007    255.583  -1.506 0.132768    
## npart        818.432    224.016   3.653 0.000294 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2936 on 395 degrees of freedom
## Multiple R-squared:  0.3898, Adjusted R-squared:  0.3837 
## F-statistic: 63.09 on 4 and 395 DF,  p-value: < 2.2e-16