Announcement

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

  • creating a line graph, taking into consideration weight

    Hello there, I've been trying to create a line graph, something similar to this. It's quite amateurish.

    The x axis - is a score, continuous variable
    I would like to plot the score for a binary variable: procedure 1, procedure 2

    My binary variables are weighted using iptw so I need to take into consideration, the weight ----> pw=_weight

    I've tried the following

    Code:
    lowess score if procedure == 1
    //// too few variables specified
    
    twoway score if procedure == 1
    //score is not a atwoway plot type
    Can you please point me in the right direction ?
    Click image for larger version

Name:	IMG_EDEDB3A6D86C-1.jpeg
Views:	1
Size:	172.3 KB
ID:	1739389




  • #2
    Although the virtues of binning are exaggerated, if this were my problem I would divide the range of your score variable into bins, and calculate means using pweights for each bin and each procedure. The fact is that many smoothing commands stop short of supporting pweights.

    Comment


    • #3
      Thank you for being helpful

      I’m sure you’re busy but would you be able to clairfy what you mean by:

      divide the range of your score variable into bins

      Would this not be categorising a continuous score variable ? Although I may not be understanding you mean and Perhaps providing an example of what you mean would really be helpful

      Comment


      • #4
        Absolutely. It would be categorising a continuous score variable, and as I said the virtues of binning are exaggerated.. I've said much more about this in various places, including https://journals.sagepub.com/doi/pdf...867X1801800311 More importantly, the references in the introduction to that paper sample the literature saying that binning is often a bad idea, which I think you're alluding to.

        But owt is better than nowt, and until someone suggests a smoothing method that supports pweights, means for binned scores are worth looking at.

        In turn you are telling is nothing about your scores. How many observations? What does the distribution look like?

        I would probably try in the first instance.

        1. Weighted means for decile bins of score by procedure.

        2. Weighted means for about 10 bins of score that have equal width, ditto.

        Comment


        • #5
          thanks for this,

          I actually found something similar to what I'm looking for......although again, I don't think it takes into consideration weights
          Which leaves me with an option to either just abandon my propensity scores using teffects (iptw) and just go for propensity score matching - this avoids using weights.
          Although ideally I would like to use my _weight options = better sample size

          Code:
          use http://www.stata-press.com/data/r13/trocolen
          
          gen group = 0
          replace group = 1 if length >300
          
          kdensity length if group == 0
          kdensity length if group == 1
          
          kdensity length, nograph generate(x fx)
          kdensity length if group == 0, nograph generate(fx0) at(x)
          kdensity length if group == 1, nograph generate(fx1) at(x)
          line fx0 fx1 x, sort ytitle(Density)
          Thanks for your suggestion @NickCox however, I'm not keen on categorizing my continuous score, in this case represented by variable - length
          Can I confirm with regards to your post:

          But owt is better than nowt, and until someone suggests a smoothing method that supports pweights, means for binned scores are worth looking at.

          Up to now is there no way to generate a method with pweights and the only alternative is binning the scores? I'm sure with Stata 18/... there must be something someone has thought of !

          Comment


          • #6
            As said, I don't know a better method but would also be interested in alternatives.

            Comment


            • #7
              Alternatively, just pretending that your pweights are aweights may allow helpful smooths to be produced. Just don't try any inference!

              Comment


              • #8
                Thank you for your kind reply

                Are P weights the same as A weights?
                I found this old post
                https://www.stata.com/statalist/arch.../msg01383.html

                The author says the P weights are the same as A weights. I can contact the author to find the source of this statement.

                However in your post(post7) you say: 'Don't try any inference'. I just want to see the score trend (x-axis) for the different treatments.

                Then again, I wonder, as I am comparing the scores for the different treatments, do I need to use the weights?
                I've generated the weights for comparison purposes for future logistic regressions. However for this graphical trend, in your expertise is the weight required? If note I can just avoid this problem.

                If this helps, I generated my weights using:

                gen attweight=pscore_iptw/(1-pscore_iptw) if $treatment == 0

                //creating weight for treatment
                replace attweight = 1 if $treatment == 1

                //Apply weights to means

                mean $xlist if $treatment == 0 [pw=attweight] //control
                mean $xlist if $treatment == 1 [pw=attweight] //treatment

                //Calculate att – section A
                reg $ylist $treatment $xlist [pw=attweight]


                P.S I don't understand why the k-density graphs don't accept Pweights....

                Comment


                • #9
                  Just try mean feeding the same variable as different kinds of weights. Standard errors usually differ and to that extent all inferences differ.

                  In that post Austin Nichols said

                  You can use aweights and get the same point estimates as pweights.
                  which is the idea behind my #7 here -- but which is a long, long way short of saying that the two kinds of weights are the same. Why implement them if so?



                  Comment


                  • #10
                    Thanks for this
                    i just don’t understand what you mean by

                    Just try mean feeding the same variable as different kinds of weights

                    do you mean for eg
                    all those observations with a score of 1 for treatment 0, take for eg the first 10 of these. Look at their weights and find the mean.

                    Then repeat for the rest of the observations, i e next 10 for score 1 for treatment 0

                    is this what you mean ?


                    Comment


                    • #11
                      The point is that the same variable presented as different kinds of weights leads to different errors. So using e.g. lpoly with your pweights presented as if they were say fweights will yield a smooth that may be helpful in description or exploration but don't ask for standard errors too, as the standard errors will be wrong.

                      Comment

                      Working...
                      X