Announcement

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

  • keep common household information only in the first row of the household

    Hi all,

    I have data set with household characteristics.
    District Village Household_ID Menber_ID Monthly_NonFood_Exp
    5 1 1 1 610
    5 1 1 2 610
    5 1 1 3 610
    5 1 1 4 610
    7 3 2 1 845
    7 3 2 2 845
    7 3 2 3 845
    7 3 2 4 845
    7 3 2 5 845
    The monthly food expenditure of the household repeats for all the household members.
    I want to keep the monthly food expenditure on the first row only.
    Simply, I want the data set to look like the following table.
    Can anyone please help me?
    District Village Household_ID Menber_ID Monthly_NonFood_Exp
    5 1 1 1 610
    5 1 1 2 .
    5 1 1 3 .
    5 1 1 4 .
    7 3 2 1 845
    7 3 2 2 .
    7 3 2 3 .
    7 3 2 4 .
    7 3 2 5 .

  • #2
    I'll explain how to do this. However, my best guess is that doing what you want is unnecessary, as changing those values to missing will not save any space, and will not enable you to do anything that you couldn't do by leaving the data as is and using "if" for certain commands. If the latter puzzles you, you might want to explain why you wanted to do this so that (if necessary) your understanding might be corrected.

    Presuming that the "first" person in each household is always the one with Menber_ID == 1, all you would need is
    Code:
    replace Monthly_NonFood_Exp = . if Menber_ID != 1
    If "first" is defined in some other way, you'll need to tell us what that is.
    (Note also "Menber" for "Member")

    Comment


    • #3
      I agree with Mike Lacy.

      One likely answer to Why do you want to do this? is So I can work household data at that level. Fine, and egen, tag() makes this much easier.


      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input byte(district village household_id menber_id) int monthly_nonfood_exp
      5 1 1 1 610
      5 1 1 2 610
      5 1 1 3 610
      5 1 1 4 610
      7 3 2 1 845
      7 3 2 2 845
      7 3 2 3 845
      7 3 2 4 845
      7 3 2 5 845
      end
      
      . egen tag = tag(district village household_id)
      
      . su monthly if tag
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
      monthly_no~p |          2       727.5    166.1701        610        845

      Comment


      • #4
        Dear Mr. Nick and Mr. Mike,
        Thank you very much for your kind reply and help.
        I actually wanted to do this, to run the balance test.
        When I try to get the balance test for treatment and control groups, I found these repeat numbers do not provide the correct balance test.
        Since I am a beginner to stata, I may wrong.
        I will try these commands that you showed me.
        Thank you once again for both of you.

        Comment

        Working...
        X