
#Replication data: Scarcity and the Mindsets of Social Welfare Recipients: Evidence from a Field Experiment

#clean environment
rm(list = ls())

#load packages

library(tidyverse)
library(lavaan)
library(haven)
library(dplyr)
library(semTools)
library(stargazer)
library(tableHTML)

#load data
kthdata <- read_sav("Replication_data_Scarcity - Anonymized.sav")

#Appendix B: Confirmatory factor analysis of latent constructs (note: to ease the flow of the replication, Appendix B is placed at the beginning as the extracted factor scores are used in all subsequent models and figures)

psych_model <- '
stress1=~ NA*s41 + a * s41 + b * s42 + c * s43 + d * s44
stress1~~ NA*stress1
s41 ~ ma*1
s42 ~ mb*1
s43 ~ mc*1
s44 ~ md*1
stress1 ~ NA*1
a + b + c + d == 4
ma + mb + mc + md == 0
autonomyloss1=~ NA*s45 + e * s45 + f * s46 + g * s47 + h * s48
autonomyloss1~~ NA*autonomyloss1
s45 ~ me*1
s46 ~ mf*1
s47 ~ mg*1
s48 ~ mh*1
autonomyloss1 ~ NA*1
e + f + g + h == 4
me + mf + mg + mh == 0
stigma1=~ NA*s49 + i * s49 + j * s50 + k * s51 + l * s52
stigma1~~ NA*stigma1
s49 ~ mi*1
s50 ~ mj*1
s51 ~ mk*1
s52 ~ ml*1
stigma1 ~ NA*1
i + j + k + l == 4
mi + mj + mk + ml == 0
'

result <- lavaan::cfa(model=psych_model, data = kthdata, missing = "ml")

#fit
fitmeasures(result)

#summary
summary(result)

#tie scores to existing dataset

kthdata[,"stress1"] <- lavaan::lavPredict(result)[, "stress1"]
kthdata[,"autonomyloss1"] <- lavaan::lavPredict(result)[,"autonomyloss1"]
kthdata[,"stigma1"] <- lavaan::lavPredict(result)[,"stigma1"]

learning_model <- '
learning1=~ NA*s53 + a * s53 + b * s54 + c * s55
learning1~~ NA*learning1
s53 ~ ma*1
s54 ~ mb*1
s55 ~ mc*1
learning1 ~ NA*1
a + b + c == 3
ma + mb + mc == 0
'

result <- lavaan::cfa(data=kthdata, model = learning_model, missing = "ml")

#fit
summary(result)

#summary
fitmeasures(result)

#tie scores to existing dataset

kthdata[,"learning1"] <- lavPredict(result)[,1]


#compliance 

compliance_model <- '
compliance1=~ NA*s56 + d * s56 + e * s57 + f * s58
compliance1~~ NA*compliance1
s56 ~ md*1
s57 ~ me*1
s58 ~ mf*1
compliance1 ~ NA*1
e + d + f == 3
me + md + mf == 0
'


result <- lavaan::cfa(data=kthdata, model = compliance_model, missing = "ml")

#fit
summary(result)

#summary
fitmeasures(result)

# tie scores to existing dataset

kthdata[,"compliance1"] <- lavPredict(result)[,1]


#mastery

mastery_model <- '
mastery1=~ NA*s14 + a * s14 + b * s15 + c * s16 + d * s17 + e * s18 + f * s19 + g * s20
mastery1~~ NA*mastery1
s14 ~ ma*1
s15 ~ mb*1
s16 ~ mc*1
s17 ~ md*1
s18 ~ me*1
s19 ~ mf*1
s20 ~ mg*1
mastery1 ~ NA*1
a + b + c + d + e + f + g == 7
ma + mb + mc + md + me + mf + mg == 0
'


result <- lavaan::cfa(data=kthdata, model = mastery_model, missing = "ml")

#fit
summary(result)

#summary
fitmeasures(result)

# tie scores to existing dataset

kthdata[,"mastery1"] <- lavPredict(result)[,1]

#subjective scarcity
subjectivescarcity_model <- '
financial=~ NA*s67 + d * s67+ e * s68+ f * s69 + g * s70
financial~~ NA*financial
s67 ~ md*1
s68 ~ me*1
s69 ~ mf*1
s70 ~ mg*1
financial ~ NA*1
e + d + f + g == 4
me + md + mf + mg == 0
'

result <- lavaan::cfa(data=kthdata, model = subjectivescarcity_model, missing = "ml")

#fit
summary(result)

#summary
fitmeasures(result)

# tie scores to existing dataset

kthdata[,"financial"] <- lavPredict(result)[,1]

#coping
coping.model <- '
problemcoping=~ NA*s1 + d * s1 + e * s2 + f * s3 + g * s4 + h * s5
problemcoping~~ NA*problemcoping
s1 ~ md*1
s2 ~ me*1
s3 ~ mf*1
s4 ~ mg*1
s5 ~ mh*1
problemcoping ~ NA*1
e + d + f + g + h == 5
me + md + mf + mg + mh == 0
avoidantcoping=~ NA*s6 + i * s6 + j * s7 + k * s8 + l * s9
avoidantcoping~~ NA*avoidantcoping
s6 ~ mi*1
s7 ~ mj*1
s8 ~ mk*1
s9 ~ ml*1
avoidantcoping ~ NA*1
i + j + k + l == 4
mi + mj + mk + ml == 0
'

result <- lavaan::cfa(data=kthdata, model = coping.model, missing = "ml")

#fit
summary(result)

#summary
fitmeasures(result)

# tie scores to existing dataset

kthdata[,"problemcoping"] <- lavPredict(result)[,1]
kthdata[,"avoidantcoping"] <- lavPredict(result)[,2]


# job search self-efficacy

efficacy.model <- '
efficacy=~ NA*s34 + d * s34 + e * s35 + f * s36 + g * s37
efficacy~~ NA*efficacy
s34 ~ md*1
s35 ~ me*1
s36 ~ mf*1
s37 ~ mg*1
efficacy ~ NA*1
e + d + f + g == 4
me + md + mf + mg == 0
'

result <- lavaan::cfa(data=kthdata, model = efficacy.model, missing = "ml")

# så tjekker vi fittet for cfa'en 

#fit
summary(result)

#summary
fitmeasures(result)

# tie scores to existing dataset

kthdata[,"efficacy"] <- lavPredict(result)[,1]


#Appendix D: Effects of experimental manipulation on subjective scarcity

#Table D1: Effects of experimental manipulation on subjective scarcity

scarcity.financial.exp <- lm(financial ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.financial.exp)

#print

stargazer(scarcity.financial.exp, title = "Table D1: Objective scarcity and subjective scarcity", type = "html")


# Appendix E: Field experimental variation in scarcity (Complier Average Causal Effects, CACE)
#reference category: High scarcity

#Table E1: Field experimental variation in scarcity and coping

#problemoriented coping

scarcity.problemoriented.exp <- lm(problemcoping ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.problemoriented.exp)

#avoidant coping

scarcity.avoidant.exp <- lm(avoidantcoping ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.avoidant.exp)

# job importance

scarcity.jobimportance.exp <- lm(s12 ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.jobimportance.exp)

# print

stargazer(scarcity.problemoriented.exp, scarcity.avoidant.exp, scarcity.jobimportance.exp, title = "Table E1: Objective scarcity and coping", type = "html")


#Table E2: Field experimental variation in scarcity and ability to navigate the system

#compliance costs

scarcity.compliance.exp <- lm(compliance1 ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.compliance.exp)

#learning costs

scarcity.learning.exp <- lm(learning1 ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.learning.exp)

#print

stargazer(scarcity.compliance.exp, scarcity.learning.exp, title = "Table E2: Objective scarcity, learning costs, and compliance costs", type = "html")


#Table E3: Field experimental variation in scarcity and psychological costs

# stress

scarcity.stress.exp <- lm(stress1 ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.stress.exp)

#stigma
scarcity.stigma.exp <- lm(stigma1 ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.stigma.exp)


# autonomy loss

scarcity.autonomyloss.exp <- lm(autonomyloss1 ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.autonomyloss.exp)

#print

stargazer(scarcity.stress.exp, scarcity.stigma.exp, scarcity.autonomyloss.exp, title = "Table E3: Objective scarcity and psychological costs", type = "html")


#Table E4: Field experimental variation in scarcity and mastery

#mastery

scarcity.mastery.exp <- lm(mastery1 ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.mastery.exp)

#job search self efficacy

scarcity.efficacy.exp <- lm(efficacy ~ Low_Dummy + Moderate_Dummy + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.efficacy.exp)

#print

stargazer(scarcity.mastery.exp, scarcity.efficacy.exp, title = "Table 2: Objective scarcity and mastery", type = "html")


# Appendix F: Subjective scarcity

# Table F1: Subjective scarcity and coping

#problemoriented

scarcity.problemoriented.exp <- lm(problemcoping ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.problemoriented.exp)

#avoidant coping

scarcity.avoidant.exp <- lm(avoidantcoping ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.avoidant.exp)

#job importance

scarcity.jobimportance.exp <- lm(s12 ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.jobimportance.exp)

#print

stargazer(scarcity.problemoriented.exp, scarcity.avoidant.exp, scarcity.jobimportance.exp, title = "Table F1: Financial strain and coping", type = "html")

# Table F2: Subjective scarcity and navigating the system

#learning costs

scarcity.learning.exp <- lm(learning1 ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.learning.exp)

#compliance costs

scarcity.compliance.exp <- lm(compliance1 ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.compliance.exp)

#print

stargazer(scarcity.compliance.exp, scarcity.learning.exp, title = "Table F2: Financial strain, learning costs, and compliance costs", type = "html")

# Table F3: Subjective scarcity and psychological costs

# stress

scarcity.stress.exp <- lm(stress1 ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.stress.exp)

#stigma
scarcity.stigma.exp <- lm(stigma1 ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.stigma.exp)

#autonomy loss

scarcity.autonomyloss.exp <- lm(autonomyloss1 ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.autonomyloss.exp)

#print
stargazer(scarcity.stress.exp, scarcity.stigma.exp, scarcity.autonomyloss.exp, title = "Table F3: Financial strain and psychological costs", type = "html")


# Table F4: Subjective scarcity and mastery

#mastery

scarcity.mastery.exp <- lm(mastery1 ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.mastery.exp)

#job search self efficacy

scarcity.efficacy.exp <- lm(efficacy ~ financial + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.efficacy.exp)

#print

stargazer(scarcity.mastery.exp, scarcity.efficacy.exp, title = "Table F4: Financial strain and mastery", type = "html")


# Appendix G: Economic support

# note: economic support is measured with item s73

#Table G1: Economic support and coping

#problemoriented

scarcity.problemoriented.exp <- lm(problemcoping ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.problemoriented.exp)

#avoidant coping

scarcity.avoidant.exp <- lm(avoidantcoping ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.avoidant.exp)

# job importance

scarcity.jobimportance.exp <- lm(s12 ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.jobimportance.exp)


#Table G2: Economic support and navigating the system

#compliance costs

scarcity.compliance.exp <- lm(compliance1 ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.compliance.exp)

#learning costs

scarcity.learning.exp <- lm(learning1 ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.learning.exp)


#Table G3: Economic support and psychological costs

# stress

scarcity.stress.exp <- lm(stress1 ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.stress.exp)

#stigma
scarcity.stigma.exp <- lm(stigma1 ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.stigma.exp)

#autonomy loss

scarcity.autonomyloss.exp <- lm(autonomyloss1 ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.autonomyloss.exp)


#Table G4: Economic support and coping

#mastery

scarcity.mastery.exp <- lm(mastery1 ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.mastery.exp)

#job search self efficacy

scarcity.efficacy.exp <- lm(efficacy ~ s73 + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata)

summary(scarcity.efficacy.exp)


#Appendix H: Subjective scarcity by gender

#first, we filter out women
kthdatamen <- kthdata %>% filter(gender == 1)

#then, we rerun all models of subjective scarcity and our dependent variables

# Table H1: Subjective scarcity and psychological costs

# stress

scarcity.stress.exp <- lm(stress1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.stress.exp)

#stigma
scarcity.stigma.exp <- lm(stigma1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.stigma.exp)

#autonomy loss

scarcity.autonomyloss.exp <- lm(autonomyloss1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.autonomyloss.exp)

#print
stargazer(scarcity.stress.exp, scarcity.stigma.exp, scarcity.autonomyloss.exp, title = "Table H1: Financial strain and psychological costs", type = "html")

# Table H2: Subjective scarcity and mastery

#mastery

scarcity.mastery.exp <- lm(mastery1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.mastery.exp)

#job search self efficacy

scarcity.efficacy.exp <- lm(efficacy ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.efficacy.exp)

#print

stargazer(scarcity.mastery.exp, scarcity.efficacy.exp, title = "Table H2: Financial strain and mastery", type = "html")

# Table H3: Subjective scarcity and navigating the system

#learning costs

scarcity.learning.exp <- lm(learning1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.learning.exp)

#compliance costs

scarcity.compliance.exp <- lm(compliance1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.compliance.exp)

#print

stargazer(scarcity.compliance.exp, scarcity.learning.exp, title = "Table H3: Financial strain, learning costs, and compliance costs", type = "html")

# Table H4: Subjective scarcity and coping

#problemoriented

scarcity.problemoriented.exp <- lm(problemcoping ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.problemoriented.exp)

#avoidant coping

scarcity.avoidant.exp <- lm(avoidantcoping ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.avoidant.exp)

#job importance

scarcity.jobimportance.exp <- lm(s12 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatamen)

summary(scarcity.jobimportance.exp)

#print

stargazer(scarcity.problemoriented.exp, scarcity.avoidant.exp, scarcity.jobimportance.exp, title = "Table H4: Financial strain and coping", type = "html")

# we then filter out men
kthdatawomen <- kthdata %>% filter(gender == 0)

#then, we rerun all models of subjective scarcity and our dependent variables

# Table H5: Subjective scarcity and psychological costs

# stress

scarcity.stress.exp <- lm(stress1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.stress.exp)

#stigma
scarcity.stigma.exp <- lm(stigma1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.stigma.exp)

#autonomy loss

scarcity.autonomyloss.exp <- lm(autonomyloss1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.autonomyloss.exp)

#print
stargazer(scarcity.stress.exp, scarcity.stigma.exp, scarcity.autonomyloss.exp, title = "Table H5: Financial strain and psychological costs", type = "html")

# Table H6: Subjective scarcity and mastery

#mastery

scarcity.mastery.exp <- lm(mastery1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.mastery.exp)

#job search self efficacy

scarcity.efficacy.exp <- lm(efficacy ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.efficacy.exp)

#print

stargazer(scarcity.mastery.exp, scarcity.efficacy.exp, title = "Table H6: Financial strain and mastery", type = "html")

# Table H7: Subjective scarcity and navigating the system

#learning costs

scarcity.learning.exp <- lm(learning1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.learning.exp)

#compliance costs

scarcity.compliance.exp <- lm(compliance1 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.compliance.exp)

#print

stargazer(scarcity.compliance.exp, scarcity.learning.exp, title = "Table H7: Financial strain, learning costs, and compliance costs", type = "html")

# Table H8: Subjective scarcity and coping

#problemoriented

scarcity.problemoriented.exp <- lm(problemcoping ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.problemoriented.exp)

#avoidant coping

scarcity.avoidant.exp <- lm(avoidantcoping ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.avoidant.exp)

#job importance

scarcity.jobimportance.exp <- lm(s12 ~ financial + age + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + ChildrenThreeormore + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdatawomen)

summary(scarcity.jobimportance.exp)

#print

stargazer(scarcity.problemoriented.exp, scarcity.avoidant.exp, scarcity.jobimportance.exp, title = "Table H8: Financial strain and coping", type = "html")


# Table 2: Descriptive statistics

descriptive_short <- kthdata %>% select(autonomyloss1, stigma1, stress1, mastery1, efficacy, compliance1, learning1, problemcoping, avoidantcoping, financial, s73, age, gender, EducationPrimary, EducationTertiary, EducationSecondary, ChildrenNone, ChildrenOne, ChildrenTwo, ChildrenThreeormore, s91, UnemploymentLengthLessThanAYear, UnemploymentLengthOnetoTwoYears, UnemploymentLengthMorethanTwoYears, UnemploymentStatusFullTime) %>%
  summarise_all(
    funs(
      NO = sum(!is.na(.)),
      ME = mean(.,na.rm = T),
      SD = sd(.,na.rm = T),
      min = min(.,na.rm = T),
      max = max(.,na.rm = T)))

descriptive_short_new <- descriptive_short %>% gather() %>% separate(key,sep="_",into=c("variabel","metric"))

descriptive_short_new_long <- descriptive_short_new %>% spread(metric, value)

View(descriptive_short_new_long)

#print

write_tableHTML(tableHTML(descriptive_short_new_long), file = 'descriptivestatsscarcity.html')

# Figure 2: Effects of Field-Experimental Variation in Scarcity

#effect estimates across dependent variables, objective scarcity (CACE)

rm(all.models)

all.models <- list()
all.models[[1]] <- scarcity.problemoriented.exp
all.models[[2]] <- scarcity.avoidant.exp
all.models[[3]] <- scarcity.jobimportance.exp
all.models[[4]] <- scarcity.learning.exp
all.models[[5]] <- scarcity.compliance.exp
all.models[[6]] <- scarcity.autonomyloss.exp
all.models[[7]] <- scarcity.stress.exp
all.models[[8]] <- scarcity.stigma.exp
all.models[[9]] <- scarcity.mastery.exp
all.models[[10]] <- scarcity.efficacy.exp


figur <- all.models %>%
  enframe() %>%
  mutate(tidy = map(value,~broom::tidy(.,conf.int = T))) %>%
  unnest(tidy) %>%
  filter(term %in% c("Low_Dummy","Moderate_Dummy"))

modelname_vector <- c(
  'Problem-focused coping (Low)',
  'Problem-focused coping (Moderate)',
  'Avoidant coping (Low)',
  'Avoidant coping (Moderate)',
  'Job importance (Low)',
  'Job importance (Moderate)',
  'Learning costs (Low)',
  'Learning costs (Moderate)',
  'Compliance costs (Low)',
  'Compliance costs (Moderate)',
  'Autonomy loss (Low)',
  'Autonomy loss (Moderate)',
  'Stress (Low)',
  'Stress (Moderate)',
  'Stigma (Low)',
  'Stigma (Moderate)',
  'Mastery (Low)',
  'Mastery (Moderate)',
  'Job search self-efficacy (Low)',
  'Job search self-efficacy (Moderate)'
)

figur$term2 <- factor(modelname_vector,level = rev(modelname_vector))

figur %>%
  ggplot(aes(x = term2, y = estimate, ymin = conf.low, ymax = conf.high,color = factor(name))) +
  geom_errorbar(width = 0) +
  geom_point(size = 2) +
  geom_hline(yintercept = 0, lty = 3) +
  coord_flip() +
  theme_minimal() +
  theme(
    legend.position = "none"
  ) + 
  labs(
    y = "",
    x = ""
  )

ggsave("figure2.tiff",width = 5,dpi = 500)


# Figure 3: Effects of Child Support Payments on Recipient Experiences

# first, remove all respondents without children living at home

kthdata_childsupport <- kthdata %>% filter(children_dummy == 1)


# stress

scarcity.stress.exp <- lm(stress1 ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.stress.exp)

#stigma
scarcity.stigma.exp <- lm(stigma1 ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.stigma.exp)


#autonomitab

scarcity.autonomyloss.exp <- lm(autonomyloss1 ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.autonomyloss.exp)

#læringsomkostninger

scarcity.learning.exp <- lm(learning1 ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.learning.exp)

#efterlevelsesomkostninger

scarcity.compliance.exp <- lm(compliance1 ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.compliance.exp)

#mastery

scarcity.mastery.exp <- lm(mastery1 ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.mastery.exp)

#job search self efficacy

scarcity.efficacy.exp <- lm(efficacy ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.efficacy.exp)

#problemoriented

scarcity.problemoriented.exp <- lm(problemcoping ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.problemoriented.exp)

#avoidant coping

scarcity.avoidant.exp <- lm(avoidantcoping ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.avoidant.exp)

# job importance

scarcity.jobimportance.exp <- lm(s12 ~ child_support + age + gender + EducationSecondary + EducationTertiary + ChildrenOne + ChildrenTwo + EthnicHeritageDanish + UnemploymentLengthOnetoTwoYears + UnemploymentLengthMorethanTwoYears + UnemploymentStatusFullTime, data = kthdata_childsupport)

summary(scarcity.jobimportance.exp)

# create figure 3

rm(all.models)

all.models <- list()
all.models[[1]] <- scarcity.problemoriented.exp
all.models[[2]] <- scarcity.avoidant.exp
all.models[[3]] <- scarcity.jobimportance.exp
all.models[[4]] <- scarcity.learning.exp
all.models[[5]] <- scarcity.compliance.exp
all.models[[6]] <- scarcity.autonomyloss.exp
all.models[[7]] <- scarcity.stress.exp
all.models[[8]] <- scarcity.stigma.exp
all.models[[9]] <- scarcity.mastery.exp
all.models[[10]] <- scarcity.efficacy.exp


figur <- all.models %>%
  enframe() %>%
  mutate(tidy = map(value,~broom::tidy(.,conf.int = T))) %>%
  unnest(tidy) %>%
  filter(term %in% c("child_support"))

modelname_vector <- c(
  'Problem-focused coping',
  'Avoidant coping',
  'Job importance',
  'Learning costs',
  'Compliance costs',
  'Autonomy loss',
  'Stress',
  'Stigma',
  'Mastery',
  'Job search self-efficacy'
)

figur$term2 <- factor(modelname_vector,level = rev(modelname_vector))

figur %>%
  ggplot(aes(x = term2, y = estimate, ymin = conf.low, ymax = conf.high,color = factor(name))) +
  geom_errorbar(width = 0) +
  geom_point(size = 2) +
  geom_hline(yintercept = 0, lty = 3) +
  coord_flip() +
  theme_minimal() +
  theme(
    legend.position = "none"
  ) + 
  labs(
    y = "",
    x = ""
  )

ggsave("figure3.tiff",width = 5,dpi = 500)

# Figure 4: Correlates between Subjective scarcity and Recipient Experiences

rm(all.models)

all.models <- list()
all.models[[1]] <- scarcity.problemoriented.exp
all.models[[2]] <- scarcity.avoidant.exp
all.models[[3]] <- scarcity.jobimportance.exp
all.models[[4]] <- scarcity.learning.exp
all.models[[5]] <- scarcity.compliance.exp
all.models[[6]] <- scarcity.autonomyloss.exp
all.models[[7]] <- scarcity.stress.exp
all.models[[8]] <- scarcity.stigma.exp
all.models[[9]] <- scarcity.mastery.exp
all.models[[10]] <- scarcity.efficacy.exp


figur <- all.models %>%
  enframe() %>%
  mutate(tidy = map(value,~broom::tidy(.,conf.int = T))) %>%
  unnest(tidy) %>%
  filter(term %in% c("financial"))

modelname_vector <- c(
  'Problem-focused coping',
  'Avoidant coping',
  'Job importance',
  'Learning costs',
  'Compliance costs',
  'Autonomy loss',
  'Stress',
  'Stigma',
  'Mastery',
  'Job search self-efficacy'
)

figur$term2 <- factor(modelname_vector,level = rev(modelname_vector))

figur %>%
  ggplot(aes(x = term2, y = estimate, ymin = conf.low, ymax = conf.high,color = factor(name))) +
  geom_errorbar(width = 0) +
  geom_point(size = 2) +
  geom_hline(yintercept = 0, lty = 3) +
  coord_flip() +
  theme_minimal() +
  theme(
    legend.position = "none"
  ) + 
  labs(
    y = "",
    x = ""
  )

ggsave("figure4.tiff",width = 5,dpi = 500)

# Extra: Reliability of key variables

samlet_model <- '
financialstrain =~ s67+s68+s69+s70
compliancecosts =~ s57+s58+s56
learningcostshh =~ s53+s54+s55
masteryhh=~s14+s15+s16+s17+s18+s19+s20
eff =~ s34+s35+s36+s37
stresshh=~s41+s42+s43+s44
autonomylosshh =~ s45+s46+s47+s48
stigmahh =~ s49+s50+s51+s52
problemcopinghh =~ s1+s2+s3+s4+s5
avoidantcopinghh =~ s6+s7+s8+s9
'

fit.full <- cfa(samlet_model, data = kthdata)

fit.full

semTools::reliability(fit.full)

#end

