Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Collapsing Nested Variable

    Hello,

    I am trying to generate a variable that indicates if more than 1/3 of the population (perc_pop_block) in a census tract (geo_id) is at least 1 mile away from a clinic (mile_1). The distance is measured at the block group level (block_group) and block groups are nested within census tracts. I can easily code this variable for tracts where one or more block groups is a mile away from a clinic
    Code:
    gen mile_33=1 if mile_1==1 & perc_pop_block>(1/3)
    but I also need to be able to create this variable for tracts for which several block groups equal more than 33% of population being further than 1 mile from a clinic. The data below represents an example for a tract in which more than 33% of the population is away from a clinic but no one block group represents more than 33%.

    I'd appreciate any help. Thank you.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str12 geo_id byte block_group float near_distance int(pop_block tract_pop) byte mile_1 float perc_pop_block
    "A29189210600" 1  .8881201 1336 6425 0 .20793775
    "A29189210600" 2 1.3657404 1443 6425 1 .22459143
    "A29189210600" 3  1.742405  711 6425 1 .11066148
    "A29189210600" 4 1.1704314 1260 6425 1 .19610895
    "A29189210600" 5  .7445323 1675 6425 0 .26070037
    end
    Last edited by Jenny Guadamuz; 03 Dec 2016, 23:27.

  • #2
    If I understand what you want (and I'm not sure I do), it is to calculate the percentage of the population of the census tract that lives in a block that has been designated with mile_1 = 1. So, you want to total up the perc_pop_block values that have mile_1 = 1 within the census tract.

    Code:
    by geo_id, sort: egen perc_pop_tract = total(mile_1*perc_pop_block)
    Is that what you wanted? (I hesitate because this is not the same thing as identifying whether 33% of the population of the census tract lives more than a mile from the nearest clinic, and I don't see a way to calculate that from the data shown.)

    Comment


    • #3
      Clyde Schechter Yes, this is what I wanted. I just couldn't wrap my head around a way to do it. I will look at the documentation for egen more carefully. Thank you!

      Comment

      Working...
      X