Announcement

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

  • pweight on twoway bar graphs

    I'm working with the World Bank Enterprise Survey dataset. I'm trying to plot a twoway bar graph with confidence intervals. How can I add pweight to the graph? Would converting pweight to fweight make sense in this case? Or is there another way to incorporate pweights into a twoway bar graph?
    Last edited by Denat Ephrem Negatu; 11 May 2022, 09:53.

  • #2
    collapse allows sampling weights, so collapse the data specifying the weights and graph. Here is an example using gr bar.

    Code:
    sysuse auto, clear
    set scheme s1mono
    gr bar mpg [pw=price], over(rep78) blab(total, format("%3.2f")) ///
    ytitle("`:var lab mpg'") ysc(r(0 25.5)) saving(gr1, replace) title("Raw data")
    
    *USING COLLAPSE
    collapse mpg [pw=price], by(rep78)
    gr bar mpg, over(rep78) blab(total, format("%3.2f")) ///
    ytitle("`:var lab mpg'") ysc(r(0 25.5)) saving(gr2, replace) title("Using collapse")
    
    *COMPARISON
    gr combine gr1.gph gr2.gph
    Res.:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	29.3 KB
ID:	1664201

    Comment


    • #3
      Thank you Andrew. However, I am collapsing so as to also get the standard errors inorder to incorporate a confidence interval on the graphs. My collapse command is as follows

      collapse (mean) mean= var_1 (sd) sd=var_1 (count) n=var_1 , by (catagory year)

      in the above command, or along anything with standard deviation, pweights don't seem to be allowed. Is there any way to address this?

      Comment


      • #4
        Thank you Andrew. However, I am collapsing so as to also get the standard errors inorder to incorporate a confidence interval on the graphs. My collapse command is as follows

        collapse (mean) mean= var_1 (sd) sd=var_1 (count) n=var_1 , by (catagory year)

        in the above command, or along anything with standard deviation, pweights don't seem to be allowed. Is there any way to address this?

        Comment


        • #5
          You can do several collapses, but I do not fully understand the problem. It may be possible to compute the standard errors using -svy- estimation, but I am not too knowledgeable in this area to advise appropriately. I would suggest starting a new thread explaining in full details what you want to do and attaching a data example so that those who have expertise in the area can advise you.

          Comment

          Working...
          X