Can I add 3 continuous independent variables and one binary categorical variable (without making dummy variables, as a dummy variable is created for more than 3 categories?) For example: one dependent variable and 3 independent variables, with the effect between 2 age groups in SPSS analyzed. Do I have to create an interaction term with all the independent variables?
1 Answer
Explanation
I'm not sure where you got information about a dummy code only being used for 3 categories...that isn't true. You can dummy code any number of categorical predictors. The core point behind it is to provide one category as the reference group and the other codes as contrasts to the reference group. So all you need is two codes: one for the first reference group and a code for the comparison group. You also don't have to use an interaction term. It depends on what you are trying to investigate with your analysis.
Example
As an example, I have simulated data below that shows three IVs and one DV. One of the predictors is a binary categorical predictor of gender, with the coding $0 = male$ and $1 = female$). I am using R here, but the idea should be essentially the same for SPSS and I show it like this to show you how dummy coding from scratch will get the result you are looking for anyway. First I create three random, normally distributed variables called y
, x1
, and x2
.
#### Simulate Data ####
set.seed(123)
y <- rnorm(n=1000)
x1 <- rnorm(n=1000)
x2 <- rnorm(n=1000)
Then I create our main variable. It is a factor that can only have values from 0 to 1, and then I label them with "Male" and "Female".
gender <- factor(
rbinom(n=1000, size = 1, prob = .5),
labels = c("Male","Female")
)
Thereafter I just smoosh all this data into a data frame and fit a regression.
#### Create Data Frame ####
df <- data.frame(x1,x2,gender,y)
#### Fit Model ####
fit <- lm(y ~ x1 + x2 + gender, data = df)
summary(fit)
If you run summary(fit)
it will give you a long output, so I have only included the relevant section below:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.08013 0.04360 1.838 0.06640 .
x1 0.08283 0.03095 2.676 0.00758 **
x2 -0.02543 0.03196 -0.796 0.42638
genderFemale -0.13999 0.06256 -2.238 0.02546 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Here you can see the gender
variable is now named genderFemale
. This is because it is being contrasted against the other level genderMale
, which is the (Intercept)
of the regression output (this is how it is done in SPSS as well). We can see that compared to the male group, the female group, after controlling for all other factors, has a conditional mean that is -.14 less than the males.
SPSS Example
I don't have SPSS installed nor do I have the space to install it again, but this video below shows a direct example of dummy coding with a binary:
-
$\begingroup$ Thanks a lot. it was helpful. yes, I had this information to create dummy variables only if the categorical variable has more than 2 categories. here I created 2 variables from age_MRA and AGE_ARA from age categorical variable and used AGE_ARA in the independent variable list to make AGE_MRA as my reference category. $\endgroup$– kaurJan 29 at 4:34
-
$\begingroup$ So long as they are used as one variable (and here two levels ARA and MRA), that would be fine. Coding them as separate variables wouldn't be super helpful. $\endgroup$ Jan 29 at 4:36
-
$\begingroup$ Thanks Shawn. So instead of creating dummy variables, I can directly add age category variable.. $\endgroup$– kaurJan 29 at 4:51
-
$\begingroup$ SPSS requires dummy coding to numerically interpret your categorical variables. So dummy code them and enter them into your regression. Also a couple notes. First, don't write answers like the two below if they are not solutions to your question...they should be reserved as comments. Second, the E-5 value is scientific notation representing a very low value. Please watch the video I linked and try the way that is prescribed there. After your variable is transformed you can enter it into a regression. $\endgroup$ Jan 29 at 5:03
-
$\begingroup$ Thanks, I was not able to post screen shot, so I added answer. I am new to this.. $\endgroup$– kaurJan 29 at 5:09