#set the working directory# setwd('C:/Users/Lindsey/Documents/AEA/AEA sample data/AEA sample data') ##import libraries used by 'memisc' - also listed in the Depends ##section of the description/documentation files library(lattice) library(grid) library(stats) library(methods) library(utils) library(MASS) library(memisc) ##Look up documentation file about R package 'memisc' help(package="memisc") ###Data screening and management functions ##read in data file survey<-read.csv(file = "surveydemo.csv", header=TRUE, sep=",") surveyDS <- data.set(survey) str(surveyDS) str(survey) str(surveyDS$survey.Income.tied.to.resources) ##Names and Renames functions names(survey) surveyR <- rename(survey, .="_" ,gsub=TRUE) names(surveyR) ##documentation data for codebook function surveyDS <- within(surveyDS,{ description(survey.Income.tied.to.resources) <- "Income depends on land or water resources Down East" wording(survey.Income.tied.to.resources) <- "Is your income currently tied to land or water resources Down East?" labels(survey.Income.tied.to.resources) <- c( Never = 3, Yes = 5, Formerly = 2 ) annotation(survey.Income.tied.to.resources)["Remark"] <- "Note: This item contained a mistype" missing.values(survey.Income.tied.to.resources)<-c(1,4) Descriptives(survey.Income.tied.to.resources) }) ##Note: For missing.values function, refer to the variable numerical category (e.g. variable code) when specifying the object to set as missing ?missing.values ##This code checks the specified object for values set as missing is.missing(surveyDS$survey.Income.tied.to.resources) ##Codebook prints all of the documentation information you previously entered codebook(surveyDS$survey.Income.tied.to.resources) ###Data Analyses ##The following code prints a vector of sample statistics Descriptives(surveyDS$survey.Age) ##This code constructs a table of summaries conditional on given values of independent variables ##given by a formula surveyDS.table<-genTable(percent(survey.Income.tied.to.resources)~survey.Community,data=surveyDS) surveyDS.table ##This code constructs a data frame of summaries conditional on given values of independent variables ##given by a formula surveyDS.agg<-aggregate(percent(survey.Income.tied.to.resources)~survey.Community,data=surveyDS) surveyDS.agg toLatex(surveyDS.table) toLatex(surveyDS.agg) surveyDS.xtabs<-toLatex(xtabs(~survey.Pace.of.development+survey.Generations.Down.East, data = surveyDS)) surveyDS.xtabs