Announcement

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

  • Generate percentiles, identify 45 &55th percentile and calculate weighted avg of 45th to 55th percentiles

    Hi everyone,

    Can anyone help me on how to generate percentiles for a variable(say food expenditure), followed by identifying the 45th and 55th percentiles from the sample, and finally calculate weighted average of 45th "TO" 55th percentiles. I followed discussion threads in the forum but I couldn't get any solutions. I am using survey data. Please help





  • #2
    Tschering:
    I'm not entirely clear with what you're after.
    Perhaps an example/excerpt of your dataset (please see -search dataex- to learn how to post it efficiently) can help.
    Anyway:
    Q1
    Code:
    pctile pct = food_expenditure , nq(100)
    Q2
    Code:
    centile food_expenditure , centile(45 55)
    Q3: I can't figure out what you mean by
    ...calculate weighted average of 45th "TO" 55th percentiles.
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Thanks Mr.Carlo,
      1). I wanted to identify food_expenditure that are at the 45th and 55th percentile across the whole sample, name these two variables as food45 and food55 (How can I create and name 2 variables as food45 and food55)
      2). And calculate the weighted average of food expenditure in the 45th to 55th percentile range. This gives the subsistence expenditure per capita, which is also the poverty line (pl)

      Many thanks Carlo!!

      Comment


      • #4
        Tshering:
        the following code accomplishes what you ask for in Q1:
        Code:
        set obs 100
        gen food_expenditure=runiform()*1000
        centile food_expenditure , centile(45 55)
        return list
        g food45=r(c_1)
        g food55=r(c_2)
        I'm still unclear with your Q2.
        Kind regards,
        Carlo
        (Stata 18.0 SE)

        Comment


        • #5
          Perhaps what you want is a 45% trimmed mean. For more see http://www.stata-journal.com/sjpdf.h...iclenum=st0313

          However, there is no easy extension of that to survey data that I know.

          Otherwise, using Carlo's code as a starting point.

          Code:
          su food_expenditure if inrange(food_expenditure, r(c_1), r(c_2))
          Last edited by Nick Cox; 06 Nov 2016, 02:58.

          Comment


          • #6
            Many thanks Mr.Carlos & Mr.Nick!

            Comment


            • #7
              for question 2, can I use loop to calculate weighted average of food_expenditure in the 45th to 55th percentile range?

              Comment


              • #8
                Hi,

                I have a similar case. What do you mean by "weighted average"? I haven't understood which is the weight in this case?

                Comment


                • #9
                  The only person who used the expression "weighted" was the OP Tshering Wangdi who hasn't been active since 10 Jan 2017. But perhaps this post will ping its way towards Tshering.

                  Interestingly, or otherwise, that turns out to be the name of a famous footballer. https://en.wikipedia.org/wiki/Tshering_Wangdi I didn't know that.

                  Comment


                  • #10
                    Thank you Nick. I think this question arises from a methodology described here (http://www.who.int/health_financing/...h_payments.pdf).

                    If you check page 3, it mentions "weighted average", but it is not further explained, or I cannot understand it.

                    Btw, I didn't know the football player, although I follow football news!

                    Comment


                    • #11
                      Hi! I have a similar prob as T Wangdi. I am analyzing a household income and expenditure survey dataset. Among others, the dataset contains the following two variables for each household:

                      total food expenditure (food_exp), and share of food expenditure in total household consumption expenditure (food_share)


                      I have to create two new variables: 45th percentile of food_share and 55th percentile of food_share. I shall have to include household weighting variable in calculating these percentile variables.

                      Then I shall have to find a value called household subsistence expenditure (hh_se) which is a weighted average of the actual total food expenditures of households associated with 45th and 55th percentile range.

                      can you please help, Mr Lazzaro or Mr Cox??

                      Comment


                      • #12
                        I don't know what's difficult here, as a search percentile points to several commands. For example, _pctile takes weights and allows those percentiles to be defined. Then you use the interval in selecting observations for some other calculation.

                        Code:
                        . sysuse auto , clear
                        (1978 Automobile Data)
                        
                        . _pctile mpg [w=price], p(45 55)
                        (analytic weights assumed)
                        
                        . ret li
                        
                        scalars:
                                         r(r1) =  18
                                         r(r2) =  20
                        
                        . scalar p45 = r(r1)
                        
                        . scalar p55 = r(r2)
                        
                        . su weight if inrange(mpg, p45, p55)
                        
                            Variable |        Obs        Mean    Std. Dev.       Min        Max
                        -------------+---------------------------------------------------------
                              weight |         20      3295.5     328.513       2410       3700
                        Last edited by Nick Cox; 19 Jun 2020, 04:16.

                        Comment


                        • #13
                          Thanks a lot, Mr Cox!!

                          Comment

                          Working...
                          X