Announcement

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

  • define size dummy of city

    Dear All, the following question is from here (https://bbs.pinggu.org/forum.php?mod...=1#pid57703787). The data set is
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id year pop)
    3 2003  200
    3 2004  500
    3 2005  600
    3 2006  700
    1 2003  600
    1 2004  800
    1 2005  900
    1 2006 1000
    2 2003  600
    2 2004  900
    2 2005 1200
    2 2006 1300
    4 2003  400
    4 2004  500
    4 2005  600
    4 2006  700
    5 2003  900
    5 2004  950
    5 2005 1000
    5 2006 1100
    end
    For each id, a "big" dummy is defined to be 1 (for all the observations in this id) if the population (pop) is larger than 500 in the year 2016, 0 otherwise. Similarly, a "medium" dummy is defined if 200 < pop < 500, and a "small" dummy is defined as pop < 200. Any suggestions? Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2

    Technique is shown by

    Code:
    egen big = total(year == 2016 & inrange(pop, 500, .)), by(id)
    as the condition

    Code:
    year == 2016 
    is presumably satisfied at most once for each city -- not at all in the example data -- and

    Code:
    inrange(pop, 500, .) 
    must be satisfied at the same time.


    Note that max() should work as total() does.

    Note that this is an FAQ!

    How do I create a variable recording whether any members of a group (or all members of a group) possess some characteristic?

    https://www.stata.com/support/faqs/d...ble-recording/

    See also https://www.stata-journal.com/sjpdf....iclenum=dm0055 for a survey of related technique.

    Comment


    • #3
      Dear Nick, Thanks again for your helpful suggestions.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment

      Working...
      X