#The code used for the negative binomial regression models #described in the ESM (not the main text) #creating loops for creating dummy variables * create 0/1 variables for every monkey, which equals 1 if the monkey appears in the dyad, 0 if the monkey does not levelsof m1, local(m1ids) foreach id of local m1ids { gen dummy`id' = (m1 == "`id'"| m2 == "`id'") } levelsof m2, local(m2ids) foreach id of local m2ids { capture gen dummy`id' = (m1 == "`id'"| m2 == "`id'") } * check that 2 of these indicator variables equal 1 on each row egen idcheck = rowtotal(dummy*) * we want idcheck to equal 2 on every row tab idcheck #DO NOT RERUN THE ABOVE TO RERUN THE MODELS if the above has been saved. #for all years together, RQI model nbreg ritualcount c.rqms i.(dummy*), exp(psgstotal) #for all years together, coalitions model nbreg ritual_count c.coalitions_rate i.(dummy*), exp(psgstotal) #for all years together, proximity model nbreg ritualcount c.sri i.(dummy*), exp(psgstotal) #for files with years as separate rows, RQI model nbreg ritual_count c.rqms i.(dummy*), exp(psgstotal) vce(cluster dyad) #for files with years as separate rows, proximity model nbreg ritual_count c.sri i.(dummy*), exp(psgstotal) vce(cluster dyad)