For purposes of this assignment, I will be using data from the 2014 General Social Survey. To see if I can come up with some data that may actually be related this time, I will be using somewhat different data than the data I had used in previous assignments that dealth with Abortions. This time, I will be comparing the relationship gender plays with various work characteristics. Hopefully I will find some interesting relationships specific to the data from 2014! Read on…
library(Zelig)
library(foreign)
library(DescTools)
d <- read.dta("/Users/laurenberkowitz/Downloads/GSS2014.DTA", convert.factors = FALSE)
names(d)
library(dplyr)
library(tidyr)
library(pander)
library(car)
ExamWork <- select(d, age, sex, marital, educ, yearsjob, wrkhome, famwkoff, famvswk, hrsrelax, satjob)
names(ExamWork)
Variables include:
AGE Respondent’s Age
SEX Respondent’s Sex
RACE Respondent’s Race
MARITAL Marital Status
EDUC Highest year of school completed
YEARSJOB Years at present job
WRKHOME Frequency of working from home
FAMWKOFF Difficulty in taking off work for family
FAMVSWK Reverse Frequency of family interfering with work
HRSRELAX Hours per week to relax
SATJOB Reverse Job Satisfaction
I want to answer the question of whether sex influences the relationship between working from home and the amount of hours per week to relax. Setting up the regression I want to see the relationship between sex and frequency of working from home.
wkeffect1 <- lm(wrkhome ~ sex, data=ExamWork)
I also look at the relationship between sex and hours per week to relax.
wkeffect2 <- lm(hrsrelax ~ sex, data=ExamWork)
In addition I want to see the relationship between frequency of working from home and hours relax.
wkeffect3 <- lm(hrsrelax ~ wrkhome, data=ExamWork)
library(stargazer)
##
## Please cite as:
##
## Hlavac, Marek (2014). stargazer: LaTeX code and ASCII text for well-formatted regression and summary statistics tables.
## R package version 5.1. http://CRAN.R-project.org/package=stargazer
stargazer(wkeffect1, wkeffect2, wkeffect3, type="html")
| Dependent variable: | |||
| wrkhome | hrsrelax | ||
| (1) | (2) | (3) | |
| sex | -0.292*** | -0.470*** | |
| (0.099) | (0.147) | ||
| wrkhome | -0.111*** | ||
| (0.042) | |||
| Constant | 2.690*** | 4.324*** | 3.860*** |
| (0.158) | (0.233) | (0.120) | |
| Observations | 1,242 | 1,233 | 1,230 |
| R2 | 0.007 | 0.008 | 0.006 |
| Adjusted R2 | 0.006 | 0.007 | 0.005 |
| Residual Std. Error | 1.746 (df = 1240) | 2.573 (df = 1231) | 2.577 (df = 1228) |
| F Statistic | 8.702*** (df = 1; 1240) | 10.289*** (df = 1; 1231) | 6.941*** (df = 1; 1228) |
| Note: | p<0.1; p<0.05; p<0.01 | ||
We see all of these relationships are statistically significant, some positive, some negative which means we can continue on to answer my question. #Simulation
We are going to simulate each of the quantities, calculate the differences, and assess significance:
sim1 <- zelig(wrkhome ~ hrsrelax + sex + hrsrelax:sex, data= ExamWork, model = "logit")
## Warning in value[[3L]](cond): There was an error fitting this statistical
## model.
## <simpleError in eval(expr, envir, enclos): y values must be 0 <= y <= 1>
##
##
## How to cite this model in Zelig:
## Kosuke Imai, Gary King, and Olivia Lau. 2015.
## "logit: Logistic Regression for Dichotomous Dependent Variables"
## in Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical Software,"
## http://gking.harvard.edu/zelig
##
Below, I have taken the data out of chunks, because I cannot figure out how to solve the errors. I know that a few other classmates mentioned that they could not figure it out either. As far as I know, I copied from the slides in class what I should have done, but I may have missed something. I also wonder if my differentiations for “sex” were incorrect. I’d love some guidance!
See below for the remainder of my codes:
xh1 <- setx(sim1, inc = mean(ExamWork\(hrsrelax)+sd(ExamWork\)inc), sex = “male”)
xl1 <- setx(sim1, inc = mean(ExamWork$hrsrelax), sex = “male”)
xh0 <- setx(sim1, inc = mean(ExamWork\(hrsrelax)+sd(ExamWork\)hrsrelax), sex = “female”)
xl0 <- setx(sim1, inc = mean(ExamWork$hrsrelax), sex = “female”)
zh1 <- sim(sim1, x=xh1)
zl1 <- sim(sim1, x=xl1)
zh0 <- sim(sim1, x=xh0)
zl0 <- sim(sim1, x=xl0)
eff <- (zh1\(qi\)ev - zl1\(qi\)ev) - (zh0\(qi\)ev - zl0\(qi\)ev)
quantile(eff, c(.025,.975))