Difference-In-Difference Regression With 1 Moderator Variable. Causal Inference.

NASDAQ=c(- 0.4, - 1.4, 0.7, 5.5, 0.3, 3.0, 5.3, - 0.5, - 9.7, 0.0, - 11.4, 11.9, 3.8, - 8.4, 7.6, 0.4, - 2.8, 1.2, 3.3, 1.2, - 6.8, - 11.2, 19.2, 9.3, 6.2, 8.5, - 5.8, - 3.4, 10.8, 4.7, 0.9, - 0.3, - 1.2, 4.1, - 2, 4.9, 1.2, 3.4, - 5.6, 6.9, 0.0, - 0.7, - 9.5, - 3.7, 3.7, - 13.6, - 2.0, - 9.4, 12.6, - 4.1, - 9.7, 3.1, 2.8, - 8.8, 9.7, - 1.0, 2.0),

Running DiD has not much to do with what's in your Excel file. That's just the source of input data. You could create your dummy variables in Excel and read them in as well, but it may well be easier in R.

The first thing to do is to create the dummy variable in R. To do that you have to know when Covid was present. From the picture you posted it looks like Covid is present in all your data, in which case you can't very well include a dummy for Covid. You also haven't told us what the second source of difference is.

If you code is short, you can just copy and paste it here. (Don't post a picture.) But the best thing to do is to make a reprex, https://forum.posit.co/t/faq-whats-a-reproducible-example-reprex-and-how-do-i-create-one/5219

1 Like

It looks like you don't have the same number of observations for the three variables in setting up your dataframe.

Is that your question?

I did see that after; I will fix this. My question is, how do I begin to transition from this multivariable LM to a DID? After I fix the same number of observations I coded where do I go from there?

A DiD requires two differences. Sounds like you will have one before and after Covid. What's the other difference?

Notice in the reference you supply that there are two dummy variables. What are your two dummies?

Nothing wrong with that equation, but it isn't a DiD.

startz,

let me apologize a second time; here is my new code and output, but I still need to add another control group time period to make it DID:

Here is some code I produced in R applying 2 dummy variables. My error was not having a second control group with reduced fed funds rates compared to the 0 and 1 dummy variables for COVID not present/present.

This is just starter code, so not "top-secret status yet. Once I have more mature code and total outputs I will share once my dissertation is approved.

My p values are high, and my adjusted R squared is negative, but this should change as I add predictors (IVs) and compare a past time series where the fed funds rate was reduced.

#create a sample data frame with 57 observations.

df <- data.frame(


fedfunds=c( 1.41, 1.42, 1.51, 1.69, 1.7, 1.82, 1.91, 1.91, 1.95, 2.19, 2.2, 2.27, 2.4, 2.4, 2.41, 2.42, 2.39, 2.38, 2.4, 2.13, 2.04, 1.83, 1.55, 1.55, 1.58, 0.65, 0.05, 0.05, 0.08, 0.09, 0.1, 0.09, 0.09, 0.09, 0.09, 0.09, 0.08, 0.07, 0.07, 0.06, 0.08, 0.1, 0.09, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.2, 0.33, 0.77, 1.21, 1.68, 2.33, 2.56, 3.08),


monthlyinflation=c( 2.04, 2.1, 2.09, 2.13, 2.14, 2.12, 2.12, 2.1, 2.12, 2.11, 2.01, 1.81, 1.79, 1.88, 1.91, 1.94, 1.83, 1.7, 1.75, 1.59, 1.59, 1.56, 1.64, 1.72, 1.72, 1.62, 0.99, 1.1, 1.12, 1.27, 1.46, 1.66, 1.66, 1.7, 1.71, 1.92, 2.08, 2.18, 2.28, 2.35, 2.47, 2.34, 2.33, 2.35, 2.34, 2.53, 2.62, 2.46, 2.45, 2.46, 2.85, 2.88, 2.69, 2.62, 2.36, 2.51, 2.38),

NASDAQ=c(- 0.4, - 1.4, 0.7, 5.5, 0.3, 3.0, 5.3, - 0.5, - 9.7, 0.0, - 11.4, 11.9, 3.8, - 8.4, 7.6, 0.4, - 2.8, 1.2, 3.3, 1.2, - 6.8, - 11.2, 19.2, 9.3, 6.2, 8.5, - 5.8, - 3.4, 10.8, 4.7, 0.9, - 0.3, - 1.2, 4.1, - 2, 4.9, 1.2, 3.4, - 5.6, 6.9, 0.0, - 0.7, - 9.5, - 3.7, 3.7, - 13.6, - 2.0, - 9.4, 12.6, - 4.1, - 9.7, 3.1, 2.8, - 8.8, 9.7, - 1.0, 2.0`))

Output:

model2<-lm(NASDAQ ~ fedfunds_dummy + covid_dummy + fedfunds_dummy*covid_dummy + monthlyinflation, data=df) summary(model2)

Call:lm(formula = NASDAQ ~ fedfunds_dummy + covid_dummy + fedfunds_dummy * covid_dummy + monthlyinflation, data = df)

Residuals: Min 1Q Median 3Q Max -13.7602 -3.7722 0.1178 4.3487 16.9942

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 5.246 5.039 1.041 0.3026 fedfunds_dummy 4.226 4.460 0.948 0.3477 covid_dummy 4.245 4.768 0.890 0.3775 monthlyinflation -4.431 2.591 -1.710 0.0933 .fedfunds_dummy:covid_dummy -2.309 5.565 -0.415 0.6799 ---Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 6.735 on 52 degrees of freedomMultiple R-squared: 0.06011, Adjusted R-squared: -0.01219 F-statistic: 0.8313 on 4 and 52 DF, p-value: 0.5114

This looks nice. Can you tell us how you define the two dummies?

I will update soon; I need to fix my dummies and add a control variable + more predictors.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.