I covered this recently in my answer to "Which test should be used to compare two mean differences?" I included code for Levene's test of unequal residuals as well, which you may want to test in your case. Because residuals were unequal in my example, I also demonstrated how a rank transformation of the outcome can improve this somewhat (though rank transformation has its drawbacks, and isn't appropriate for all circumstances). Last, I noted some debate on whether independent-samples $t$-tests on pre-post differences would be appropriate as an alternative – it seems to depend somewhat on whether your samples were really sampled randomly.
In your case, I imagine the code for a DID general linear model would look something like this:
summary(lm(VOLUME~scale(PRE.VOLUME,scale=F)*DUMMYTIME,yourdata))
In the above, yourdata
is a data.frame
with PRE.VOLUME
and VOLUME
as separate columns for stock exchange volume before and after the law, and DUMMYTIME
as a dummy-coded binary variable for differentiating your two samples. If your interaction term (scale(PRE.VOLUME,scale=F):DUMMYTIME
) is fairly large and reliable ("significant", basically), interpret sample differences with caution, because that means another violated assumption in DID / ANCOVA. If it doesn't, you can take the interaction term out of the model by replacing the *
with a +
as in @JeremyMiles' example.
You can use the ggplot2
package to visualize the regression lines for each sample on a scatterplot:
ggplot(yourdata,aes(x=PRE.VOLUME,y=VOLUME,colour=factor(DUMMYTIME)))+geom_point()+
stat_smooth(method='lm',formula=y~scale(x,scale=F))