I am trying to perform a logistic regression with the lm() function in R. My model is: lm(xrd ~ VariableA*Post, data = DatasetXRD), this is a difference-in-differences model, the R code is based on: https://www.princeton.edu/~otorres/DID101R.pdf.
Some general info regarding my data:
I have applied pseudo adoption in my model (in the Post variable). So I state that some companies will apply a certain rule after a year even though they do not apply it. However VariableA will remain 0 (no application of the rule) for these companies. This will result into a value of 1 for companies that do apply it, and a value of 0 for companies that do not apply it (in that specific year, it could be that they will apply it in a later year).
VariableA and Post are both dummy variables (value= 0 or 1).
The third row of text in my lm table is showing NAs.
Coefficients: (1 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 43286 4865 8.897 <2e-16 ***
VariableA 4900 6362 0.770 0.441
Post -4904 6849 -0.716 0.474
VariableA:Post NA NA NA NA
As shown in the table this is because of singularities. After a google search I have found that this is because of collinearity.
I have run the cor() function trying to see if this would lead to a perfect correlation, since that would proof that I have collinearity issues, but I don't find the results convincing (am I making a thinking error here?)
cor(Dataset$VariableA, Dataset$Post)
This leads to the following output: 0.5890362. Correlation is not 1, so that does not mean that my independent variables are not perfectly collinear (in my own words: they do not perfectly explain each other?)
I have also ran:
alias(didreg, complete = TRUE, partial = FALSE,
partial.pattern = FALSE)
I have read in a previous question that was similar that this will show collinearity, however I will admit that I do not fully understand how to interpret the output of the table below.
Model :
xrd ~ VariableA * Post
Complete :
(Intercept) VariableA Post
VariableA:Post 0 1 0
I do not understand why I am having collinearity problems. My Variable A and Post variable are correlated, but only for 0.58, not for 1...
If I have missed some important pieces, please let me know.
Thanks in advance for any help!
Kind regards
glm()
rather thanlm()
if you really want logistic regression. For the stats part, collinearity just means that one variable can be written as a linear combination of others:z
might not be perfectly correlated withx
ory
, but you have collinearity if you can finda
andb
so thatz
is perfectly correlated withax + by
(or similarly with more than 2 in the linear combination). $\endgroup$