Could someone please take a look at a line of code and tell me where I am going wrong. Of my 3,000 US counties, I have 50 counties with a county police agency (agencysamptype == 700) and a county sheriff's agency (agencysamptype == 1) that have the same value of POPESTIMATE2010, which equals the agency's population served/policed in 2010. Other counties have a county police department and a county sheriff's office but with different population served values. I am trying to generate an indicator equal to 1 when a county has a county police department and a county sheriff's office with the same value of POPESTIMATE2010. I tried two different codes based on things I read online, but neither are working. Once I create the indicator, I would like to apply the result to every observation in the county, even agencies that are not county police departments or sheriff's offices. Any help with this code would also be much appreciated.
Code 1:
by fstate fcounty, sort: gen samepop = cond(POPESTIMATE2010/(agencysamptype == 1) == POPESTIMATE2010/(agencysamptype == 700), 1, 0)
Based on: https://www.stata.com/support/faqs/d...ng-properties/
Code 2:
sort fstate fcounty agencysamptype POPESTIMATE2010
by fstate fcounty, sort: gen samepop = cond(POPESTIMATE2010[1] == POPESTIMATE2010[_N], 1, 0)
Based on: https://www.stata.com/support/faqs/d...ions-in-group/
Thank you for your time!
Tom
Related Posts with Creating an indicator for when different observations in a group have the same value on a variable
Looping over folders in the directory and then over files in each folderHi everyone, I want to make a panel data dta file from several excel files sitting in several folde…
How to drop the duplicates with the fewest missing values?I have duplicates that share values, but some are missing. I would like to keep the observation of e…
Generating a variable that is gives average score based on 'yes' responses on a bunch of variablesHello experts, I have been facing a challenge in producing an output that is based on average score…
Fractional response model with binary endogenous explanatory variableHello everyone, As the title mention, I have an endogenous explanatory variable, which happens to be…
Why there is missing t-test information for one controlling variable after using PSM and ptest?Array Dear friends, I applied PSM using below command, psmatch2 treat x1 x2 , out(Y) logit ate neig…
Subscribe to:
Post Comments (Atom)
0 Response to Creating an indicator for when different observations in a group have the same value on a variable
Post a Comment