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
Drop entire individual if number of outliers exceeds threshold levelHello everyone, for a dataset that contains many countries, I have generated a tag that shows me ou…
putting the legend to the bottom layer How to do that? Array …
Descriptive statistics for two categoriesHey statistic pros, I try to make a descriptive statistic for my logistic regression. It should be …
hausman test interpretationdear statalists, I got hausman test result ---- Coefficients ---- | (b) (B) (b-B) sqrt(diag(V_b-…
Nested foreach and forvalue for fixed effect analysis (using xtreg), with saving outputsHi, I am completely new to STATALIST, STATA and some "decent" econometrics, in general. Therefore, …
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