# Datasets and software

### Software: Stata and R

In this module, instructions for fitting the models will be provided for two statistical software packages, Stata and R. We assume that you are reasonably familiar with the use of at least one of these packages in general.

For R, you will need to install an additional package called lavaan. Please click here for more information on installing this package

### Datasets

The Stata data file was obtained by downloading the full ESS5 Stata data file from the ESS website. It was then reduced to the file used here by keeping only the 15 variables listed in the previous section, plus the variables *idno* (respondent ID) and *cntry* (country of the respondent).

The Stata file was then imported into R using the *read.dta* function from the *foreign* package in R, and saved from R as *ESS5Police.RData*.

If you started with a dataset in SPSS, you could save it as a Stata data file directly from SPSS. To import the SPSS data file into R, you could use the *read.spss* function from the *foreign* package in R.

Begin by downloading the data file *ESS5Police.dta* (for Stata) or *ESS5Police.RData* (for R) by clicking on the links below:

- Download the Stata data file
- Download the R data file

In Stata, you then open the data file using the File → Open menu, and in R using the File → Load Workspace menu.

### Command files

Stata and R commands for data preparation and data analysis exercises for these data are given throughout this module. All of the commands for these different steps are also included in single files which you can download by clicking on the links below:

- Download the Stata do file
- Download the R script file

### Preliminary analysis: Missing values and recoding some items

Before you can start analysing the data, you should carry out the following two steps of data processing:

- Coding the values of the variables which should be regarded as missing in such a way that the software will treat them as missing values.
- Reversing the coding of the items D21-D23 (variables
*plcrgwr*,*plcipvl*and*gsupplc*) as discussed in the previous section.

Stata commands: To run this and any other commands included in this module, you can copy and paste them into the do-file editor in Stata, and run the commands from there. These commands assume that you have first opened the data file *ESS5Police.dta* in Stata, as described above. After you run the commands here, save the data file again to save the changes.

R commands: : To run this and any other commands included in this module, you can copy and paste them into the script editor in R, and run the commands from there. These commands assume that you have first loaded the data into R, as described above. After you run these commands, the data will be in the data frame *ESS5Police*, ready for the analyses.