First of all, you are supposed to go to the following website:

http://www.cdc.gov/niosh/mining/data/default.html

You can download MSHA Data Files from there (in zipped format, yearwise, .sav – SPSS files within, for last 30 years)

I downloaded all the files, unzipped and converted into RDS file, if you want to save time, you can download the file from the link below:

Download file from -> HERE

Download Data Dictionary 1 file from -> HERE

And, Download Data Dictionary 2 file from -> HERE

##############################################

Script for reading all the files in a folder.. U can use if you want to convert all the unzipped files into R Data Frame.

! Warning!

Make sure that you have only .SAV files in the folder you are reading these files from, otherwise you will be on pains.

my_file_list <- list.files()

library(foreign)

#dataset = read.spss(my_file_list, to.data.frame=TRUE)

for (myfile in my_file_list){
 
  # if the dataframe mydataset doesn’t exist, create it
  if (!exists(“mydataset”)){
    mydataset <- read.spss(myfile, to.data.frame = T)
  }
 
  # if the merged mydataset exists, append data from next files into it
  if (exists(“mydataset”)){
    
    my_temp_dataset <- read.spss(myfile, to.data.frame = T)
    
    mydataset <- rbind(mydataset, my_temp_dataset)
    
    rm(my_temp_dataset)
    
  }
}

rm(my_file_list)
rm(myfile)

# save the file in the default working directory
saveRDS(mydataset, “mydataset.rds”)

############################################

Creating project space

# loading data from files
AIdata1 <- readRDS(“./aidata.rds”, refhook = NULL)

# viewing if the data is loaded correctly
AIdata1[1, ]
# Should work OK.

str(AIdata1)

###########################################

Now all’s done and data ready for the analysis, I want you to perform some statistics on it and revert as reply to this post….

I would really appreciate the useful posts (replies) as they could help other readers.

Advertisements