Mac *.txt.rtfd to *.txt

In a recent project, an assistant used TextEdit to supposedly save documents as pure (UTF-8) text files. We managed to fix the workflow, but I was left with a bunch of Zip files full of *.rtf from TextEdit. On a Windows or GNU/Linux machine, these files show up as what they are: folders that contain a rich text document (and potentially other stuff). I needed text documents.

After a bit of searching and tweaking, I got the following shell script to convert all the rich text documents in these folders/containers into text documents:

find . -name '*.rtf' -exec unoconv -f txt {} \;

There was a problem, though. The files all had a name containing important meta data. So I had the folder with the name of the file, and inside this folder the file but it was called TXT.txt (converted from TXT.rtf). I’m sure there’s a quick way in a shell script (if you know one, please share it in the comments), but I got stuck with the shell.

Enter LiveCode. Here’s a script that does just that. I guess I could have called the above shell script, but I already had this.

on mouseup
-- INPUT: select a folder with the *.txt.rtfd folders
answer folder "Input: Choose folder:"
put it into infoldername
set the defaultFolder to infoldername
put the folders into listoffolders
-- filter . and .. can cause problems
filter listoffolders without "."
filter listoffolders without ".."
-- OUTPUT: select a destination folder
answer folder "Output: Choose folder:"
put it into outfoldername
repeat with i = 1 to the number of lines of listoffolders
put line i of listoffolders into currentfolder
revCopyFile infoldername & slash & currentfolder &
slash & "TXT.txt", outfoldername & slash & textname
end repeat
end mouseup

Full LiveCode stack here on OSF (it’s nothing more than a button and a text field with a basic log).

“Why Don’t Immigrants Vote More?” — Participation in Local Elections Published

paMy paper on the electoral participation of immigrants in local elections is now available online (Parliamentary Affairs). As part of this research, I spoke to a politician who exclaimed: ‘Why don’t they [immigrants] vote now that we have given them the opportunity?’. It’s the expectation that all ‘we’ have to do is enfranchise immigrants, and they’ll flock to the ballot boxes. But, they don’t.

In the paper I present a new representative survey of participation in the 2015 municipal elections in the Canton of Geneva. The cleaned data (and replication material) are available at IQSS Dataverse; the raw data at FORS.

In Geneva, foreign citizens who have lived in Switzerland for at least 8 years have the right to vote in local elections. In 2015, the chancellor wrote a personal letter to each of them to invite them to vote, yet most immigrant groups vote less than the majority population. In the paper I test four common explanations for this difference in electoral turnout: social origin (resources), political engagement, civic integration and networks, as well as socialisation. Individually, all these explanations are associated with differences in electoral participation, but contrary to some recent studies, substantive differences between nationalities remain in the local elections in Geneva.

Overcoming Warnings when Importing SPSS Files to R

R can import SPSS files quite easily, using the package foreign and the read.spss command. It usually works quite well out of the box, so well that I usually choose the SPSS file when downloading secondary data (hint: look at the argument use.value.labels depending on how you want your data).

Sometimes R isn’t so happy, throwing warnings like “Unrecognized record type 7, subtype 18 encountered in system file”. Generally warnings in R are there for a reason. Usually these seem to be variable and data attributes in SPSS, but to be sure, simply convert the SPSS file into SPSS Portable (*.por rather than *.sav). Don’t have SPSS? Enter PSPP , a free (open source) program that can help you out! (for Windows, check directly on this site).

pspp-saveas-por PSPP can open SPSS files faster than SPSS, and under File > Save as... there’s the option to save as a Portable file (rather than the default System File) at the bottom left of the dialog. If you import this (portable) SPSS file to R, there should be no errors or warnings.

Need Data from the SOM Project? You Can!

From time to time I get asked when the data from the SOM Project on the politicization of immigration will be available. It’s already there!

The principal data have been available from the project Dataverse for a while now. Many more details and coding instructions are available from the Data section of the project website.

To catch up on the main findings of the SOM project, get a copy of The Politicisation of Migration (Routledge, 2015). Other publications are listed on the project website.

MIPEX since 1848

In a new paper we explore how Swiss immigration and integration policies have developed in Switzerland between 1848 and 2014. The Swiss Political Science Review have done a marvellous job in getting this into print in a astonishing short time (share your experience at scirev…). Policies are covered in true MIPEX style, that is 7 policy areas and a total of 148 indicators. We recorded the situation at the national level for every year, and you can get the full data here.

Ruedin, D., Alberti, C. and D’Amato, G. (2015), Immigration and Integration Policy in Switzerland, 1848 to 2014. Swiss Political Science Review. 21(1): 5-22. doi: 10.1111/spsr.12144