FIND DATA: By Journal | Sites   ANALYZE DATA: Help with R | SPSS | Stata | Excel   WHAT'S NEW? US Politics | IR | Law & Courts🎵
   FIND DATA: By Journal | Sites   WHAT'S NEW? US Politics | IR | Law & Courts🎵
WHAT'S NEW? US Politics | IR | Law & Courts🎵

Run R Code Example Online

library(poliscidata)  # run every time

# Creating a numeric indicator variable
gss$veteran = gss$vetyears != "NONE"    # Any years of service yields TRUE
gss$veteran = as.numeric(gss$veteran)   # TRUE and FALSE values now 1s and 0s

# the freq dist tables not strictly necessary but you should check your work
cat("Frequency Distribution Table (Original Variable):\n")
freq(gss$vetyears, plot=F)             # Make sure indicator variable correct

cat("\nFrequency Distribution Table (New Variable):\n")
freq(gss$veteran, plot=F)              # by comparing frequencies