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
Selecting the last few letters, when substr(.) is not appropriateHello all, I have data that resembles the following: ----------------------- copy starting from …
GMM Panel Data on StataHi, I have a dynamic model where the dependent variable is lagged. Therefore I am using system-GMM a…
F-Test or T-TestHi guys, I have a question that is not regarding to Stata particually but to statistics in general.…
List of localsHi Statalist! I need to make a list of some locals defined in the .do file, in order to verify if t…
Abbreviate all String Observations in a ColumnHi all, I have a column variable containing only 3- or 4-digit string observations. I just converte…
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