# Explore contents of variable in dataset
#############################################################
library("poliscidata")
# You need to load the poliscidata package each time at the start of each session/script.
# You should also always set a working directory, but this demo script is running on a remote server.
#############################################################
# Explore specific variable in the NES dataset: opinions about death penalty.
# The deathpen variable is the 370th variable/column in our NES dataset, so it is nes[,370]
# Rather than reference by column number, it is much easier to reference it by name.
# To keep the output simple, we are only viewing first 20 observations.
# The levels() command shows you all the unique values of a variable.
cat("First 20 responses to death penalty question in the dataset:\n")
nes$deathpen[1:20]
cat("\n\nLevels of the variable values:\n")
levels(nes$deathpen)
# Describe national opinions about the death penalty using table and figure.
# Use sample weights so the statistics are nationally representative.
cat("\n\nFrequency Distribution Table:\n")
freqC(nes$pid_x, nes$wt)