Getting Qualtrics data into R

Data collected in Qualtrics come in a funny way when exported to CSV: the first two lines are headers. Simply using read.csv() will mess things up, because typically we only have one line as header. We can skip empty lines at the beginning, but there is no immediately obvious way to skip only the second line.

Of course there is an R package for that, but when I tried, the qualtRics package was very slow:

raw_data <- readSurvey("qualtrics_survey.csv")

raw_data <- readSurvey("qualtrics_survey_legacy.csv", legacyFormat=T) # if two rows at the top

As an alternative, you could import just the header of your survey, and then join it to an import where you skip the header lines. Actually, here’s a better way of doing just this:

everything = readLines("qualtrics_survey_legacy.csv")
wanted = everything[-2]
mydata = read.csv(textConnection(wanted), header = TRUE, stringsAsFactors = FALSE)

If you get an error “EOF within quoted string”, don’t ignore it: It indicates problems with double quoting, so add quote = "" to your import code.

If you are willing to violate the principle of not touching the raw data file, you could open the survey in a spreadsheet like Excel or LibreOffice Calc and delete the unwanted rows.

Given all these options, I found the most reliable way (as in: contrary to the above, it hasn’t failed me so far) to get Qualtrics data into R yet another one:
1. export as SPSS (rather than CSV)
2. use library(haven)
3. read_spss()

Anonymizing Microdata

In the age of datalinkage, protecting microdata is as relevant as ever. Fortunately, there are R packages available to help:

That’s another excuse for not sharing data busted.

Out now: Participation in Local Elections: ‘Why Don’t Immigrants Vote More?’ in Parliamentary Affairs

My paper on the political participation of immigrants in the local elections of Geneva is now properly published at Parliamentary Affairs. In the article, I present a new representative survey on participation in the 2015 municipal elections in the Canton of Geneva, Switzerland, and predict electoral participation with logistic regression models (predicted probabilities all around). Most immigrant groups vote less than the majority population. Social origin (resources), political engagement, civic integration and networks, as well as socialization are associated with differences in electoral participation, but contrary to some recent studies, substantive differences between nationalities remain.

The paper has its origins in a commissioned report Rosita Fibbi and I did (in French, executive summary in French). The research question is summarized in the (abbreviated) quote in the title: the sentiment that “we” have given “them” the right to vote in local elections (after 8 years of residence in the country), and yet they “don’t” vote (well not as often than “we” do). Quite fortunately we managed to convince the office of integration of the Geneva to allow us to make the survey data available to the academic community (cleaned version). The survey deliberately re-uses questions from the Swiss Electoral Study to enable a direct comparison, but Rosita and I added questions relevant to the research question and participation at the local level. The article is an independent analysis from the report, having spent more time on the topic that the rushed context of commissioned research allows.

Ruedin, Didier. 2018. ‘Participation in Local Elections: “Why Don”t Immigrants Vote More?’’. Parliamentary Affairs 71 (2): 243–262.