Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using R studio to answer the questions. My code always wrong! Thanks for help # Learning outcomes: # 1. Tabulating numerical data by categories of

Using R studio to answer the questions. My code always wrong! Thanks for help

# Learning outcomes: # 1. Tabulating numerical data by categories of qualitative variables - Arsenal package. # 2. Creating dummy variables for categories of qualitative variables. # 3. Inserting tables and figures into a Word Document (Thesis). # 4. Estimating multiple regression models with dummy variables and  # interpreting the results. rm(list=ls()) #rm(list of objects) removes all objects from workspace graphics.off() #Closing all previously open graphs # Installing package for reading Stata data sets if (!require("stargazer")) install.packages("stargazer") #Publication quality tables if (!require("arsenal")) install.packages("arsenal") #Create descriptive summary statistics tables if (!require("rmarkdown")) install.packages("rmarkdown") #Document formatting #Attach the packages library("stargazer") library("arsenal") library("rmarkdown") #**************************************************************************************** # Study: How Union Membership Affects Race Earnings Gaps? * #**************************************************************************************** # 1. Load the data lacated at "http://online.sfsu.edu/mbar/ECON312_files/nlsw88.csv" # into data.frame "nlsw".  #  # NLSW stands for "National Longitudinal Surveys of Women". # Data consists of working women, ages 34 - 46. #  # Key variables: # wage - hourly earnings (in $ per hour) # tenure - the number of years worked at current job # grade - years of schooling # race - qualitative variable with categories {"black", "white", "other"} # union - qualitative variable with categories {"union", "nonunion"}, some missing value. #  # Complete the code between the lines: #________________________________________________________________________________________ nlsw <- read.csv( , stringsAsFactors = TRUE) # Changing the reference race category to "white". nlsw$race <- relevel(nlsw$race, ref="white") #Make "white" the reference category levels(nlsw$race) #To see levels (categories) of factor variable #________________________________________________________________________________________ # 2. Rename the variable "grade" to "S". # Complete the code between the lines: #________________________________________________________________________________________ names(nlsw)[names(nlsw)=="grade"] <- #Renaming the variable #________________________________________________________________________________________ # 3. Create an "arsenal" table with summary statistics of the key variables: # {wage, tenure, S, race, union}. # Complete the code between the lines: #________________________________________________________________________________________ # Generating the table with "arsenal" package. tab <- tableby( ~ wage + tenure + , data = nlsw, control = tableby.control(test = FALSE, total = FALSE)) # Presenting the table in the console (not publication qulity) summary(tab, text = TRUE, title = "NLSW: Key Variables") # Saving html table (publucation quality) write2html(tab, "nlsw1.html", title = ) # Saving .docx table (publication quality) write2word(tab, "nlsw1.docx", title = ) #________________________________________________________________________________________ # 4. Create an "arsenal" table with summary of wage by categories of race. # Complete the code between the lines: #________________________________________________________________________________________ # Generating the table with "arsenal" package. tab <- tableby(race ~ wage, data = nlsw, control = tableby.control(test = FALSE, total = FALSE)) # Presenting the table in the console (not publication qulity) summary(tab, text = TRUE, title = "Summary of Wage by Race Categories") # Saving html table (publucation quality) write2html(tab, "nlsw2.html", title = ) # Saving .docx table (publication quality) write2word(tab, "nlsw2.docx", title = ) #________________________________________________________________________________________ # 5. Create an "arsenal" table with summary of wage by union membership. # Complete the code between the lines: #________________________________________________________________________________________ # Generating the table with "arsenal" package. tab <- tableby( ~ , data = nlsw, control = tableby.control(test = FALSE, total = FALSE)) # Presenting the table in the console (not publication qulity) summary(tab, text = TRUE, title = "Summary of Wage by Union Membership") # Saving html table (publucation quality) write2html(tab, "nlsw3.html", title = "Summary of Wage by Union Membership") # Saving .docx table (publication quality) write2word(tab, "nlsw3.docx", title = "Summary of Wage by Union Membership") #________________________________________________________________________________________ # 6. Create an "arsenal" table with summary of union membership by race. # Complete the code between the lines: #________________________________________________________________________________________ # Generating the table with "arsenal" package. tab <- tableby( , data = nlsw, control = tableby.control(test = FALSE, total = FALSE)) # Presenting the table in the console (not publication qulity) summary(tab, text = TRUE, title = "Summary of Union Membership by Race") # Saving html table (publucation quality) write2html(tab, "nlsw4.html", title = "Summary of Union Membership by Race") # Saving .docx table (publication quality) write2word(tab, "nlsw4.docx", title = "Summary of Union Membership by Race") #________________________________________________________________________________________ # 7. Create a box plot of wage by combinations of union with race categories. The box plot # formula is wage ~ union*race. Use the "Paired" color palette from the "grDevices"  # package. # Complete the code between the lines: #________________________________________________________________________________________ windows(width=10, height=5) #Use this if you have Windows OS # quartz(width=10, height=5) #Use this if you have Mac OS boxplot(wage ~ union*race, data=nlsw, main="Wage by Race and Union Membership", ylab="Hourly Wage, $ per hour", outline = FALSE, col=palette.colors(n = 6, palette = )) # Saving the figure dev.copy(png, "nlsw.png", height = 5, width = 10, units = 'in', res = 300) dev.off() #Returns control to the screen, after saving the file #________________________________________________________________________________________ # 8. Create a set of dummy variables for race categories and a dummies for  # union membership.  # Complete the code between the lines: #________________________________________________________________________________________ nlsw$W <- ifelse(nlsw$race=="white", 1, 0) #Dummy for white nlsw$B <- #Dummy for black nlsw$O <- #Dummy for other nlsw$U <- ifelse(nlsw$union=="union", 1, 0) #Dummy for union member nlsw$NU <- #Dummy for non union member #________________________________________________________________________________________ # 9. Estimate 3 models of earnings: # (1) wage ~ B + O + U + tenure # (2) wage ~ B + O + U + tenure + S # (3) wage ~ B + O + U + tenure + S + B*U + O*U # Complete the code between the lines: #________________________________________________________________________________________ model1 <- lm( , data=nlsw) summary(model1) model2 <- model3 <- #________________________________________________________________________________________ # 10. Create stargazer table with model1, model2, model3. # Complete the code between the lines: #________________________________________________________________________________________ stargazer(model1, , type = "text", #How to display in console ("text", "html") title = "Estimated Models of Wages", intercept.bottom = FALSE, report = "vc*", single.row = TRUE, #If we want se next to coefficient, and eliminate vertical spaces out="models_nlsw.htm", digits=3) #out - saves the table #________________________________________________________________________________________ 

These are questions

Summary Tables

Summary of key variables in "nlsw" data set

Paste the table "nlsw1.docx"created with arsenalpackage here.

Summary of wage by race categories

Paste the table "nlsw2.docx"created with arsenalpackage here.

Summary of wage by union membership

Paste the table "nlsw3.docx"created with arsenalpackage here.

Summary of union membership by race

Paste the table "nlsw4.docx"created with arsenalpackage here.

Graphical Summary of Wage by Race & Union Membership

Insert your figure "nlsw.png"here.

Estimation Results

Paste the table "models_nlsw.htm"created with stargazerpackage here.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linear Algebra A Modern Introduction

Authors: David Poole

3rd edition

9781133169574 , 978-0538735452

More Books

Students also viewed these Mathematics questions