Announcement

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

  • Collapsing individuals into census tracts?

    Hello,

    My dataset is geocoded and a census tract code is attached to each individual. I also have census tract data (aka % poverty, % white, etc.) for the each census tract in the U.S. I used the many to one merge code and now the datasets are merged. But now I want to collapse individuals into census tracts and then delete the rest of the census tracts that don't contain any individuals. I tried the collapse code, collapse childid, by(tract) and I get a 'type mismatch' error code. Any advice how to collapse the individuals into census tracts? Or perhaps different merging advice? I would be so grateful for any advice!

    Carlyn

  • #2
    it appears that "childid" is a string variable; if you look at the help for collapse, you will see that it must be numeric; however, it is not clear why you want to collapse; if you just want to id tracts without any individuals, the result of _merge should have told you which these were (either _merge=1 if the census tract data was your master or _merge=2 if the census tract data was your "using" file; note that the values 1 and 2 refer to unmatched observations); however, possibly I am completely misunderstanding your goal as it is completely unclear to me why you want to -collapse-

    Comment


    • #3
      If that command is giving you a type mismatch error, it means that childid is a string variable. So you can't calculate a mean of that. Even if childid were numeric, so that a mean could, in principle, be calculated, if, as the name suggests, it's just an id code, it doesn't sound like it would be meaningful.

      I imagine that what you really want to do is aggregate up the average values of poverty, white, etc per tract. So if poverty and white are coded 0/1, then the code would be:

      Code:
      collapse (mean) poverty white, by(tract)
      The -(mean)- part isn't strictly necessary because that's the default statistic for -collapse-, but I generally prefer to make these things explicit so that the code is maximally easy to read, even for people not intimately familiar with the default options of Stata's commands.

      Added: Crossed with #2. Rich Goldstein focuses more on the part about eliminating tracts with no individuals represented in your data. His comments are, as always, wise and correct. I largely ignored that part and focused on figuring out what you might have wanted to do with -collapse-.

      Comment

      Working...
      X