Announcement

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

  • Calcultating Household Diet score(HDDS)

    I trying to calculate an HDDS score which is basically a sum of food types that a household has consumed in the last 24hr. Each food type is coded 1 for Yes or 0 for No where calculating it by hand is just adding all the ones for each household; the max score number should be 12 for 12 food types. Using this principle I thought it was simply creating an HDDS variable and then replacing it with an addition of all the food types but it doesn't seem to be that simple.

    This is what I did but it returns fewer observations than expected
    gen HDDS =.
    replace HDDS = FD_CEREAL+FD_SUGAR+FD_OIL+FD_PULSES+FD_FISH.......

    Thanks for your help
    Mona

  • #2
    Mona:
    it might be that the -rowtotal- function of the -egen- command is what you're looking for.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      To expand a bit on Carlo's suggestion, you can save yourself some typing by using -egen, rowtotal-, because Stata accepts wild cards.

      In the example you provide, all your 12 food categories start with FD_, so you can use this:

      Code:
      egen HDDS = rowtotal(FD_*)
      and this will add all the food categories starting with FD_ .

      Comment


      • #4
        Thanks alot Carlo and Joro, your combined advise has helped me solve me solve the problem!

        Comment

        Working...
        X