Announcement

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

  • weights not allowed problem with pctile

    Dear all,

    I try to calculate percentiles to weighted data. According to the manual it should be allowed, but command

    . egen medi = pctile (indkri13) [w=wgt], p(50) by(xdate)

    causes error "weights not allowed" and r(101). Obviously something goes wrong, but I can not figure out what.

    The version of the Stata is 12.1 for 32-bit Windows, Revision 08 Aug 2012.

    Sincerely,
    JP

  • #2
    Jan,

    Weights are allowed on the pctile command , but not when using the egen pctile() function. The equivalent pctile command is:

    Code:
    bys xdate: pctile medi=indkri13 [w=wgt], nq(2)
    This command, however, only puts the median in the first observation for each by group, after which you will have to populate the remaining observations with that value.

    Regards,
    Joe

    Comment


    • #3
      Dear Joe,

      Thank you for your fast response. Ok, that explains, and also solves, my problems.

      Sincerely,
      Jan

      Comment


      • #4
        I have the same problem, but when I use pctile with by I get an error:
        . bys age: pctile prova=fin [fweight=fwgt], nq(10)
        pctile may not be combined with by
        r(190);
        How did you solve?Do I have to use "if"?How?

        Comment


        • #5
          I'd recommend starting with cumul and getting yourself cumulative distribution functions. Then you bin them, which sounds like ceil() applied to 10 x the cumulative probability.

          That said,

          1. Values with frequency weights tend to be even more difficult to get into equally populated bins than values in general, as the difficulty of ties is exacerbated.

          2. Tribal habits differ, but being in the 7th quantile bin of something given an age category is for my money further from anything causal or mechanistic from having a value of something. Otherwise put, what's the logic of this kind of calculation?

          Comment


          • #6
            I want to plot three lines on a graph, where x axis is age and y is financial wealth(or others similar): lines correspond to different percentiles of wealth, given the age. I am studying saving behaviour over life cycle.
            I followed your advice, which I think is a good idea, but I stil have a probelm: the weighted percentiles are the same as the unweighted ones.My code is:
            PHP Code:
            bysort agecumul fin [fweight=fwgt], generate(cum_fin)
            sort age cum_fin
            gen cum_fin_100
            =cum_fin*100
            replace cum_fin_100
            =ceil(cum_fin_100)
            gen FinLC25=fin if cum_fin_100==26 cum_fin_100[_n-1]==25 
            Where fin is financial wealth

            Comment


            • #7
              Code isn't legal as underscores are often omitted. More importantly, I don't see any evidence here for your claim.

              Comment


              • #8
                Since you show no results (requested in the FAQ Section 12), then, as Nick said, there is no evidence for your claim. Moreover, you did not follow his recipe for making 10 bins; you made 100.
                Steve Samuels
                Statistical Consulting
                [email protected]

                Stata 14.2

                Comment

                Working...
                X