
OPTIONS SAMPLEWITHREPLACEMENT=FALSE MINIMIZEMEMORY=TRUE SHUFFLE=TRUE SEED=10. *This uses a custom function I made to restrict matches to within 500 meters.įUZZY BY=EST2_1 XMeters YMeters SUPPLIERID=MarID NEWDEMANDERIDVARS=Match1 Match2 Match3 GROUP=HalfwayHouse CUSTOMFUZZ = "DistFun.DistFun" The function takes the probability of treatment along with the two spatial coordinates of the street unit. Also with the custom function you can do more complicated things, like my second buffer function. here something like FUZZ = 0.02 500 500), but this produces a box, not a circle. Without the custom function you could specify the distance in any one dimension on the FUZZ command (e.g. Now we can use the FUZZY command and supply our custom function. (Note that this is not permanent change to the PATH system variable in windows, and is only active in the same SPSS session.) *Testing out my custom function. So back in SPSS we can add the folder to sys.path and check that our function is importable. 1) Also have the file _init_.py in the same folder (Jon Peck made the comment this is not necessary), and 2) add this folder to the system path. To make this an importable function in SPSS for FUZZY you need to do two things. Now to make the research reproducible, what I do is save this python file, DistFun.py, in the same folder as the analysis. (In this dataset my coordinates are projected in meters.) The second function is another example if you want matches not too close but not too far away, at a distance of between 5. It then calculates the euclidean distance, and returns a 1 if the distance is under 500 and the absolute distance in propensity scores is under 0.02. The first function DistFun, takes a list where the first two elements are the coordinates, and the last element is the probability of treatment. The FUZZY command expects a function to return either a 1 for a match and 0 otherwise, and the function just takes a fixed set of vectors. #distance under 500, and caliper within 0.02 Here I made a file named DistFun.py, and placed in it the following functions: #These functions are for SPSS's fuzzy case control matching The model is very bad, but we can see that sidewalk cafes are never associated with a halfway house! (Again this is just an illustration – don’t take this as a serious analysis of the effects of halfway houses on crime.) Now we need to make a custom function with which to restrict matches not only based on the probability of treatment, but also based on the geographic location. PLUM HalfwayHouse WITH NonViol SidewalkCafe TypeC_D FREQ HalfwayHouse.ĬOMPUTE Viol = OffN1 + OffN4 + OffN5 + OffN6.ĬOMPUTE NonViol = OffN2 + OffN3 + OffN7 + OffN8 + OffN9. I use non-violent crimes, sidewalk cafes, and bars as predictors. Then I use PLUM to fit the logistic model predicting the probability of treatment. The frequency shows there are only 9 halfway houses in the city, and the compute statements collapse crimes into violent and non-violent. Do not take this as a serious analysis, just as an illustration of the workflow. Now as a quick illustration, I am going to show a propensity score analysis predicting the location of halfway houses in DC – and see if street units with a halfway house are associated with more violence. TotalCrime HalfwayHouse SidewalkCafe TypeC_D. MATCH FILES FILE = * /KEEP MarID XMeters YMeters OffN1 OffN2 OffN3 OffN4 OffN5 OffN6 OffN7 OffN8 OffN9 FILE HANDLE save /NAME = "!!!Your Handle Here!!!".
#Modul spss 20 update
Note to follow along you need to update the file handle to your machine. This dataset are street segments and intersections in DC, and the variables are crime, halfway houses, sidewalk cafes, and bars. So first lets grab the data and reduce it down a bit to only the variables we will be using.
#Modul spss 20 code
To illustrate I will be using some example data from my dissertation, and the code and data can be downloaded here. To do this I used the FUZZY extension command, which allows you to input a custom function. The other day I needed to conduct propensity score matching, but I was working with geographic data and wanted to restrict the matches to within a certain geographic distance.
