Announcement

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

  • Returning zero (0) for collapse (count)

    Hi all,

    I'm trying to create a list of observation counts, across a subset of data [census tracts] using an "if" command. I'd like Stata to return "0" for observations that don't satisfy the "if" command.

    Currently:
    collapse (count) x if x>50, by(tract)

    gives a list of tracts that satisfy the if command, but excludes tracts that don't. I'd like to include the tracts that don't satisfy the command with value of "0"

    Any recommendations? Many thanks.

    Jay

  • #2
    Code:
    help contract
    if here is a qualifier, not a command. There is an if command, but you're not using it.

    EDIT: Second thoughts. That won't work here. You need something else. I'll get to this later today if someone else doesn't beat me to it.


    EDIT 2:

    Code:
    gen x2 = x > 50 
    collapse (sum) x2,  by(tract)
    Watch out for missings.
    Last edited by Nick Cox; 16 Jul 2018, 12:56.

    Comment

    Working...
    X