Announcement

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

  • Generating household size

    Hello everybody,
    I am a master student, working on my thesis. I do not know how to generate a variable that contains the hh size, I want to use it as a control variable for my regression.
    Basically I have a roster dataset that contains 25,335 observations. Out of this individual observations I have 6,679 households.
    The variable hhid shows me the codes for every household, for example: two individuals with the code 102 compromise one hh, and so on.
    I need help in creating the new variable hh_size

  • #2
    Klisman:
    maybe something along the following lines will do the trick:
    Code:
    use "http://www.stata-press.com/data/r15/nlswork.dta"
    bysort idcode: egen size=total(idcode)
    replace size=size/idcode
    Kind regards,
    Carlo
    (StataNow 19.0)

    Comment


    • #3
      Another approach would be
      Code:
      bysort idcode: generate size = _N

      Comment


      • #4
        thank you very much for the precious help

        Comment

        Working...
        X