## ---------------------------------------- ##

## Regression with Categorical X variables  ##

## Author: Tony Cookson                     ##

## Date: 1 March 2011                       ##

## ---------------------------------------- ##

## ------------ ##

## Read in Data ##     See Video R2 for how to do it this way.

## ------------ ##

library(foreign)

edu.df = read.dta("C://R//edudat.dta")

## ------------ ##

## Explore Data ##

## ------------ ##

names(edu.df)

summary(edu.df)

length(edu.df[,1])   ## Length of first column.  Gives # of observations

edu.df$gender

## ------------------- ##

## Run a Regression    ##

## ------------------- ##

wage.lm1 = lm(log(wage)~gender, data = edu.df)

summary(wage.lm1)

wage.lm2 = lm(log(wage)~educ+exper+gender, data=edu.df)

summary(wage.lm2)

wage.lm3 = lm(log(wage)~educ+exper+exper:gender+gender, data = edu.df)

summary(wage.lm3)

## ------------------- ##

## Run a Regression    ##

## on "Male" subsample ##

## ------------------- ##

wage.lm4 = lm(log(wage)~educ+exper,data=edu.df[edu.df$gender=="MALE",])

summary(wage.lm4)

wage.lm5 = lm(log(wage)~educ+exper,data=edu.df[edu.df$gender=="FEMALE",])

summary(wage.lm5)