2.2 Load your dataset

The command you will use to load the dataset depends on the type of file you have downloaded.

Make sure to place your file in the R project folder!

2.2.1 Loading a World Values Study dataset

You can load the dataset by either the point and click method or by typing the command below in your R script file.

To point and click:

  1. Select Import Dataset in the upper-right quadrant.
  2. Select From SPSS
  3. Browse (in the upper right) and find your file.
  4. You can rename the file (bottom left). (Once you type, select out of the box.)
  5. Add , user_na = TRUE) %>%as_factor() to the end of code so the line reads like the example below.
  6. Click on the Import button.

Here is an example. You can name yours what you want. The structure is nameYouGiveIt <- read_dta(“NameOfTheFileInYourDirectory.dta”, user_na = TRUE) %>% as_factor())

ethiopia <- read_sav("WVS_Wave_7_Ethiopia_Spss_v1.5 2.sav", user_na = TRUE) %>%
  as_factor()
View(Ethiopia)

Once you have loaded the file, you should now use the following code to clean up your data. Don’t load this package until now! Replace ethiopia with the name of your file that you just loaded.

## Don't load this package until now!
library(sjlabelled)

ethiopia <- set_na(ethiopia, na = c("No answer", "Don´t know", "Other missing; Multiple answers Mail (EVS)", "Not asked"), drop.levels = TRUE)

Watch a video on opening a WVS dataset.

2.2.2 Loading a states dataset

You can load the dataset by either the point and click method or by typing the command below in your R script file.

To point and click:

  1. Select “Import Dataset” in the upper-right quadrant.
  2. Select “From Excel”.
  3. Browse (in the upper right) and find your file.
  4. You can rename the file (bottom left). (Once you type, select out of the box to apply it.)
  5. In the NA box in the bottom left, type NA. (Once you type, select out of the box to apply it.)
  6. Click on the “Import” button.

I am using the Ethiopia file as an example. You can name yours what you want. The structure is nameYouGiveIt <- read_excel(“NameOfTheFileInYourDirectory.xlsx”, na = “NA”)

myStatesData <- read_excel("cspp_data_2021-02-14.xlsx", )
View(myStatesData) 

Watch a video on opening a WVS dataset.

2.2.3 Loading a Gapminder dataset

If you have collected Excel files and sent them to me, your file is already in .Rdata format.

You can click on it in the file tab (lower-right quadrant). Click on the Yes button to confirm.

You can also type the command below in your R script file:

load("yourFileName.Rdata")

Watch a video on opening a WVS dataset.

2.2.4 View your dataset

You can view your data in the upper-right quadrant by running the view command (replace your dataset name in the parentheses, no need for quotation marks here):

view(Ethiopia)

Or you can click on the small spreadsheet icon to the right of your dataset name in the upper-right quadrant.

Watch a video on viewing your data