Announcement

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

  • How to generate a total and share of expenditure?

    Hi,

    Can you please tell me how I can generate a total value for the variable listed below and then create a share for each variable(e.g. wexp_grains/total)? An example would be useful.

    Code:
     
    wexp_grains wexp_frveg wexp_pulses wexp_meat wexp_fish wexp_milkda wexp_drinkbev wexp_oilsfat wexp_others
    Thanks,
    Mohamud

  • #2
    *** begin code ***
    egen wexp_total = rowtotal(wexp_*), missing
    foreach x in grains frveg pulses meat fish milkda drinkbev oilsfat others {
    gen share_`x' = wexp_`x' / wexp_total
    }
    *** end code ***
    // ivica_rubil //

    Comment


    • #3
      Thank you Ivica.

      I took the approach you suggested but got a result that I did not expect. As you would see wexp variable from which I calculated the total and share expenditures resulted in 'no observations' despite the fact the wexp has a mean and range values.

      Can you help me please to understand what is going on, and suggest an alternative approach to overcome the problem?

      Code:
       
      sum wexp_grains wexp_frveg wexp_pulses wexp_meat wexp_fish wexp_milkda wexp_drinkbev wexp_oilsfat wexp_others
      Variable Obs Mean Std. Dev. Min Max
      wexp_grains 74,936 2.13377 .7073587 1.211606 4.009885
      wexp_frveg 124,895 1.789554 .7799143 .8157954 3.692125
      wexp_pulses 27,755 1.529597 .5298207 .12 2.064826
      wexp_meat 39,080 3.928044 2.320698 .5922232 7.026239
      wexp_fish 11,816 4.106419 1.545911 2.055259 5.845754
      wexp_milkda 23,752 3.583346 2.261793 .893132 6.690858
      wexp_drink~v 31,444 2.808646 .969089 1.707988 5.07098
      wexp_oilsfat 23,547 2.341372 .6586063 .9970102 3.128694
      wexp_others 116,800 1.973933 1.794487 .5076035 8.734041
      .
      . *generating share of weekly expenditure food for each food category
      . egen wexp_total = rowtotal(wexp_*), missing
      . foreach x in grains frveg pulses meat fish milkda drinkbev oilsfat others {
      2. gen swexp_`x' = wexp_`x' / wexp_total
      3. }
      (399,089 missing values generated)
      (349,130 missing values generated)
      (446,270 missing values generated)
      (434,945 missing values generated)
      (462,209 missing values generated)
      (450,273 missing values generated)
      (442,581 missing values generated)
      (450,478 missing values generated)
      (357,225 missing values generated)
      . sum swexp_grains swexp_frveg swexp_pulses swexp_meat swexp_fish swexp_milkda swexp_drinkbev swexp_oilsfat swexp_others
      Variable Obs Mean Std. Dev. Min Max
      swexp_grains 74,936 1 0 1 1
      swexp_frveg 124,895 1 0 1 1
      swexp_pulses 27,755 1 0 1 1
      swexp_meat 39,080 1 0 1 1
      swexp_fish 11,816 1 0 1 1
      swexp_milkda 23,752 1 0 1 1
      swexp_drin~v 31,444 1 0 1 1
      swexp_oils~t 23,547 1 0 1 1
      swexp_others 116,800 1 0 1 1
      .
      end of do-file

      Comment


      • #4
        What does missing means in your data? Does it mean zero expenditure or truly missing data?
        // ivica_rubil //

        Comment


        • #5
          zero expenditure

          Comment


          • #6
            Then, before you run the code I suggested, just replace all missings for all expenditure variables by zero.
            Because, if you don't, then the share of an expenditure category cannot be computed for those observations for which the amount of this very expenditure category is missing; whereas if missings are replaced by zero, it can be computed (it will be zero, of course).
            // ivica_rubil //

            Comment


            • #7
              Hello, I am working with household survey data. how do I calculate household expenditure from the individual household member expenditures

              Comment


              • #8
                Welcome to Statalist.

                This question isn't really a followup to the original topic. You will perhaps see a larger audience if you post it as a new topic in this forum by clicking on

                General

                and in the page that opens, click on the button labelled "+ New Topic" near the top of the page.

                Also, if you have not already done so, take a look at the Statalist FAQ linked to at the top of this page for posting guidelines and suggestions.

                Comment

                Working...
                X