I'm using Stata 17 on a Mac. I have a more substantive question on mapping, but first I have a quick question on how to best create a reproducible example for Statalist. I'm trying to create a binary variable "pnc" (received postnatal care, yes/no) with 0s and 1s that varies randomly across individuals. I want the county-level average percentages of mothers who received postnatal care to vary for my example because this is the variable I am mapping. Below is the code I used so far. I'm sure there is a more concise way to create the random binary variable pnc and this code gets even more clumsy if I need more than 10 observations. For a previous example, I used something like gen pnc = cond(mod(_n, 2), 0,1), but I don't want the pattern to be regular for this. Would be grateful if you could point me in the right direction to help with creating reproducible examples for Statalist posts!
Code:
clear set obs 10 gen id = _n gen pnc = 1 if id==1 replace pnc = 1 if id==2 replace pnc = 1 if id==3 replace pnc = 0 if id==4 replace pnc = 1 if id==5 replace pnc = 0 if id==6 replace pnc = 0 if id==7 replace pnc = 0 if id==8 replace pnc = 1 if id==9 replace pnc = 0 if id==10 gen county = "" replace county = "Kilifi" in 1/2 replace county = "Meru" in 3/5 replace county = "Nyeri" in 5/10 lab define pnc 0 "No" 1 "Yes" lab values pnc pnc
Comment