Code for table does not recognize a variable | Doing Economics EMPIRICAL PROJECT 8

Hi everyone,

I have the following issue. I'm currently working on the following project The thing is, I have to create a table with countries (3 of them) as the rows and the differences in the means of certain variables (namely, life satisfaction for three conditions of employment - full time, unemployed, retired), the standard errors of these differences and the confidence interval width for these differences. The code for doing this is given. It is the following


List chosen countries

country_list <- c("Turkey", "Spain", "Great Britain") <- lifesat_data %>%

Select Wave 4

subset(S002EVS == "2008-2010") %>%

Select the employment types we are interested in

subset(X028 %in% employment_list) %>%

Select countries

subset(S003 %in% country_list) %>%

Group by country and employment type

group_by(S003, X028) %>%

Calculate the standard error of each group mean

summarize(se = sd(A170) / sqrt(n())) %>%
spread(X028, se) %>%

Calculate the SE of difference

mutate(D1_SE = sqrt(Full time^2 + Unemployed^2),
D2_SE = sqrt(Full time^2 + Retired^2))

df.employment <- df.employment %>%

Select chosen countries

subset(S003 %in% country_list) %>%

We only need the differences.

select(-Full time, -Retired, -Unemployed) %>%

Join the means with the respective SEs

inner_join(.,, by = "S003") %>%
select(-Full time, -Retired, -Unemployed) %>%

Compute confidence interval width for both differences

mutate(CI_1 = 1.96 * D1_SE, CI_2 = 1.96 * D2_SE) %>%

However, when running the second chunk of code I get the following error "Error: object 'D1_SE' not found". Now, what's weird is that the original code works. However, the error occurs when I attempt to change the 3 countries mentioned in the 1st chunk above. The code chunks related to the variable D1 are the following:


Set the employment types that we want to report

employment_list = c("Full time", "Retired", "Unemployed")
df.employment <- lifesat_data %>%

Select Wave 4

subset(S002EVS == "2008-2010") %>%

Select only observations with these employment types

subset(X028 %in% employment_list) %>%

Group by country and then employment type

group_by(S003, X028) %>%

Calculate the mean by country/employment type group

summarize(mean = mean(A170)) %>%

Reshape to one row per country

spread(X028, mean) %>%

Create the difference in means

mutate(D1 = Full time - Unemployed,
D2 = Full time - Retired)

df.employment %>%

Combine with the average work ethic data

inner_join(., df.work_ethic, by = "S003") %>%
ggplot(., aes(y = D1, x = mean_work)) +
geom_point(stat = "identity") +
xlab("Work ethic") + ylab("Difference") +
ggtitle("Difference in wellbeing
between the full-time employed and the unemployed") +
theme_bw() +

Rotate the country names

theme(axis.text.x = element_text(
angle = 90, hjust = 1),
plot.title = element_text(hjust = 0.5))

Full-time vs unemployed

cor(df.employment$D1, df.work_ethic$mean_work)

and the two given above

Please, help me out with this. Thank you for your time.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.