Discussion_5

Author

Angelo Marinaro

#Packages list
library(stargazer)

Please cite as: 
 Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
 R package version 5.2.3. https://CRAN.R-project.org/package=stargazer 
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(ggplot2)

I. Diff-n-Diff

A.

dt1 <- read.csv("us_fred_coastal_us_states_avg_hpi_before_after_2005.csv")

B. Regression

\[ HPICHG_i = \beta_0 + \beta_1 Timeperiod_i + \beta_2 Disasteraffected_i + \beta_3 Timeperiod_i \ * \ Disasteraffected_i + \epsilon \]

reg1 <- lm(data = dt1,
           formula = HPI_CHG ~ Time_Period +  Disaster_Affected +  Time_Period * Disaster_Affected)
stargazer(reg1,
          type = "text")

=========================================================
                                  Dependent variable:    
                              ---------------------------
                                        HPI_CHG          
---------------------------------------------------------
Time_Period                            -0.028***         
                                        (0.004)          
                                                         
Disaster_Affected                      -0.014**          
                                        (0.006)          
                                                         
Time_Period:Disaster_Affected           0.020**          
                                        (0.009)          
                                                         
Constant                               0.037***          
                                        (0.003)          
                                                         
---------------------------------------------------------
Observations                              48             
R2                                       0.536           
Adjusted R2                              0.504           
Residual Std. Error                 0.012 (df = 44)      
F Statistic                     16.916*** (df = 3; 44)   
=========================================================
Note:                         *p<0.1; **p<0.05; ***p<0.01

C.

1.

The control group are states that were not affected by any disaster, more specifically, the observations that have a 0 on Disaster_affected.

The treatment group are states that were affected by any disaster, more specifically, the observations that have a 1 on Disaster_affected.

2.

When using DID, the goal is to isolate the treatment effect on a variable of interest. We look at the difference between the treatment group and the control group. We achieve this by looking at the difference between the average outcome of our treatment group (observed) and the average outcome of a hypothetical treatment group that did not receive the treatment. This works because of the basic assumption that the treatment group would have followed a similar pattern as the control group had the treatment not being applied.

time <- c(1, 2, 3, 4, 5)  
treatment_outcomes <- c(11, 12, 13, 14, 20)  
control_outcomes <- c(10, 11, 12, 13, 14) 
hypothetical_outcomes <- c(11, 12, 13, 14, 15) 

df <- data.frame(time = rep(time, 3),
                 group = rep(c("Treatment", "Control", "Hypothetical"), each = length(time)),
                 outcomes = c(treatment_outcomes, control_outcomes, hypothetical_outcomes))  

# Plotting
ggplot(df, aes(x = time, y = outcomes, color = group, linetype = group)) +
  geom_line(size = 1) +
  labs(x = "Time", y = "Outcomes", color = "Group", linetype = "Group") +
  ggtitle("Difference-in-Differences (DID) Graph") +
  scale_linetype_manual(values = c("Treatment" = "solid", "Control" = "solid", "Hypothetical" = "dashed")) + 
  geom_segment(aes(x = max(time), xend = 5 , y = max(treatment_outcomes), yend = max(hypothetical_outcomes)) ,
               color = "black", size = 1) +  
  theme_minimal() 
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

The blue line is the treatment group

The red line is the control group

The dashed line is the hypothetical case where the treatment group did not receive the treatment

The black line represents the difference in difference effect

3.

mean_table <- tapply(dt1$HPI_CHG, list(Time_Period = ifelse(dt1$Time_Period == 0, "pre", "post"),
                                       Treatment_Status = ifelse(dt1$Disaster_Affected == 0, "control", "treatment")),
                    mean)

print(mean_table)
           Treatment_Status
Time_Period     control  treatment
       post 0.009242792 0.01503835
       pre  0.037090020 0.02314612
DiD_effect <- (mean_table[1, 2] - mean_table[2, 2])  - (mean_table[1, 1] - mean_table[2, 1])
print(DiD_effect)
[1] 0.01973946

D. Assumptions

No Spillover Effects

The treatment does not have direct or indirect effects on the control group

No Other Contemporaneous Events

There are no events that affect both the treatment and control group differently

Sufficient Time Periods

There are enough pre-treatment and post-treatment time periods to observe trends.

Homogeneous Treatment Effects

The treatment effect is homogeneous across all units.

It is important to understand that these assumptions are the building base of the DID models, if they are violated, then the models could contain bias so each study done with DID have to carefully evaluated to test the robustest and the accuracy of the results.