research paper using R
PSC 370 American Judicial Politics Data Lab #2
1
(1) Go to Blackboard
• Download your justice data file (clark.dta) o Create a new folder (psc 370 project) o Save justice data file in “psc 370 project”
• Download the Codebook o Save it in “psc 370 project”
Open R Misc > Change Working Directory Select folder (“psc 370 project”) Install R Packages #only need to do this once install.packages(“car”) install.packages(“descr”) install.packages(“readstata13”)
You only need to do the above once; everything else below you do every time! Turn On R Packages Packages & Data > Package Manager Click on “car”, “descr”, “readstata13” Or library(car) #check that they’re installed using Package Manager library(descr) library(readstata13) Open R Document File > New Document #do all of your coding/typing in this document and save it #copy and paste from this document to R Read Data into R clark<-read.dta13(“clark.dta”) #may need to manually type this in #ignore warning messages
PSC 370 American Judicial Politics Data Lab #2
2
(2) Names of Variables names(clark) #this lists all of the variables in your dataset
#notice the similarities/differences in names of variables freq(clark$direction) #60 Direction of Individual Justice’s Vote is direction in R #decisions are coded as liberal and conservative freq(clark$issueArea) #A14 Issues Areas in Codebook is issueArea in R #combines all issues into 14 broad areas #notice the frequencies (number of cases) in each category freq(clark$issue) #A13 Issues in Codebook is issue in R #a large variety of issue areas #notice the frequencies (number of cases) in each category
#there are other variables to use based on your hypotheses, #but these are common to everyone
Coding requires precision. If you get an error it’s probably because you missed a “ , ‘ or ).
Coding Dependent Variable freq(clark$direction) levels(clark$direction) clark$dv=as.numeric(clark$direction=="liberal") freq(clark$dv) #note the total number of cases, number of
#conservative and liberal decisions and the #percentages
#2132, Conservative (978, 45.87) Liberal (1154, 54.13) Coding Independent Variables freq(clark$issue) levels(clark$issue) (a) unions clark$unions<-recode(clark$issue, "'arbitration, labor'=1; 'union antitrust'=1;'union or closed shop'=1;'Fair Labor Standards Act'=1;'Occup. Safety Health Act'=1;'labor-mgt bargaining'=1;'labor- mgt discharge'=1;'labor-mgt distr. of union lit.'=1;'labor-mgt rep. election'=1;'labor-mgt antistrike injunc.'=1;'labor-mgt right to organize'=1; 'labor-mgt picketing'=1;'labor-mgt 2ndary activity'=1; 'labor-mgt no-strike clause'=1;'labor-mgt union rep.'=1; 'labor-mgt union trust fund'=1;'labor-mgt work conditions'=1;'labor-mgt misc.dispute'=1;else=0") #notice that “labor-mgt” omits the ‘:’
PSC 370 American Judicial Politics Data Lab #2
3
freq(clark$unions) #note the frequency and percent of cases #52 cases, 2.269% (b) subversive activities clark$reds<-recode(clark$issue, "'sit-in demonstrations'=1;'legislative investigations'=1;'Fed. internal security leg.'=1;'loyalty oath'=1;'loyalty oath bar applicants'=1;'loytalty oath govt. employ.'=1;'loyalty oath political party'=1;'loyalty oath teachers'=1;'security risks'=1;'conscientious objectors'=1;'protest demonstrations'=1;else=0") #notice that “loyalty oath” omits the ‘:’ freq(clark$reds) #87 cases, 3.796% (c) race and civil rights clark$race<-recode(clark$issue, "'voting'=1;'Voting Rights Act of 1965'=1;'desegregation'=1;'desegregation, schools'=1;else=0") freq(clark$race) #76 cases, 3.316% (d) corporations freq(clark$issueArea) levels(clark$issueArea) clark$corp<-recode(clark$issueArea, "'Economic Activity'=1;else=0") freq(clark$corp) #548 cases, 23.91% (e) joining Warren’s majority opinions freq(clark$majOpinWriter) clark$warrenmow<-recode(clark$majOpinWriter, "'EWarren'=1; else=0") freq(clark$warrenmow) #147 cases, 6.414% By the end of Lab #2, you should have your dependent variable and all independent variables coded. Send me the R code for each variable.