
Note that the estimate of the interaction effect looks like this: -įuture0_1000_7 | Coef. I think an arrest will reduce that probability. Here I am predicting whether a burglary has a follow up near-repeat crime (within 1000 feet and 7 days). Now I estimate my logistic regression model, with my interaction effect and the global $ContVars control variables I specified earlier.
LINE GRAPH STATA CODE
If you look at my replication code for my paper though, I ended up doing this same thing for four different crimes and two different estimates, so I wanted as automated approach that avoids as many magic numbers as possible. This may seem overkill, as I could just fill in those values by hand later.

*I will need this later to draw the margins over the support Too few and the plot may not look smooth, too many and it will take margins forever to calculate the results.

The Grid global will then tell Stata how often to calculate those effects. To do that in Stata, I use summarize to get the min/max of that historical crime density and pipe them into a global. Or stated another way, the historical crime density variable basically ranges from 0 to 2.5 in the sample - I don’t care what the interaction effect is then at a historical crime density of 3. When displaying that interaction effect though, I only want to limit it to the support of the historical crime density in the sample. I am predicting whether a crime results in a near-repeat follow up - hot spots with more crime on average will have more near-repeats simply by chance. So basically what I want to do in the end is to draw an interaction effect between a dummy variable (whether a crime resulted in an arrest) and a continuous variable (the historical crime density at a location). *For here I am just examining burglary incidents Global ContVars "d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 whiteperc blackperc hispperc asianperc under17 propmove perpoverty perfemheadhouse perunemploy perassist i.month c.dateint" *control variables used in the regression *Making the previous densities per time period Import delimited CrimeStrings_withData.csv Finally for simplicity in this script I am just examining the burglary incidents, so I get rid of the other crimes using the keep command. One trick I like to use with regression models with many terms is to make a global that specifies those variables, so I don’t need to retype them a bunch. I read in the data as a CSV file, generate a new variable that is the weekly average number of crimes within 1000 feet in the historical crime data (see the working paper for more details). That will be more productive than me commenting on every individual line. Again check out Ben Jann’s awesome website he made an all the great examples. Here is what I did to change my default graph settings. Net set ado "C:\Users\axw161530\Documents\Stata_PlugIns\V15" *let stata know to search for a new location for stata plug insĪdopath + "C:\Users\axw161530\Documents\Stata_PlugIns\V15" Log using "LogitModels.txt", text replace *Set the working directory and plain text log fileĬd "C:\Users\axw161530\Dropbox\Documents\BLOG\Stata_NiceMargins\Analysis" But it is good for others to know what extra packages they need to fully replicate your results.
LINE GRAPH STATA INSTALL
The code is currently commented out, as I only need to install it once. So I add a location to adopath that is on my machine, and I also do net set ado to that same location.įinally, for here I ssc installed grstyle and palettes. I don’t have write access there, so to install commands I need to set my own place to install them on my local machine. The next part is partly idiosyncratic to my Stata work set up - I call Stata from a centralized install location here at EPPS in UTD. I use set more off so I don’t have to do the annoying this and tell Stata to keep scrolling down.

Start Upįirst in my do file, I have a typical start up that sets the working directory and logs the results to a text file.

Data and code to follow along can be downloaded from here.
