elem econ homework

profileshazuanzhe
hypothesistesting2.R

treat<-subset(introtoR, healthins==1) control<-subset(introtoR, healthins==0) avgdiff<-mean(treat$health)-mean(control$health) #I had previously made a typo here, the answer is still the same, but the previous code I had here only works when the treatment and control groups have the same number of individuals #t-test for equality of average age between treatment and control group t.test(treat$age, control$age) #t-test for equality of proportion of females t.test(treat$female, control$female) #t-test for equality of proportion of family heart disease t.test(treat$famheart, control$famheart) #one-sided t-test for equality of average age between treatment and control group t.test(treat$age, control$age, alternative="less") #one-sided t-test for equality of proportion of females t.test(treat$female, control$female, alternative="greater") #t-test for equality of average age between treatment and control group t.test(treat$age, control$age, mu=10) #t-test for mean value of age in entire sample t.test(introtoR$age, mu=40) t.test(introtoR$age, mu=40, conf.level=0.99) reg1<-lm(health~healthins, data=introtoR) summary(reg1) reg2<-lm(health~healthins+age+female+famheart, data=introtoR) summary(reg2) #log wages on education, experience, and tenure reg3<-lm(log_real_wage~years_of_education+years_of_experience+tenure_at_current_job, data=school_test) summary(reg3) #Creating a new variable equal to the sum of education and experience school_test$educexper<-school_test$years_of_education+school_test$years_of_experience #modified model for test of equality of returns to education and experience reg4<-lm(log_real_wage~years_of_education+educexper+tenure_at_current_job, data=school_test) summary(reg4) #Same as above, just adding the variables together inside the formula reg5<-lm(log_real_wage~years_of_education+I(years_of_education+years_of_experience)+tenure_at_current_job, data=school_test) summary(reg5) #restricted model for F test below regres<-lm(log_real_wage~years_of_experience, data=school_test) summary(regres) #test exclusion of education and experience #ln(wage)=a+d(tenure)+u #H0: b=0,c=0 # anova(restricted lm, unrestricted lm) anova(reg3, regres)