Announcement

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

  • How to use weights on graph twoway bar?

    Greetings,

    I have the code below and I want to know how I can add the sample weight variable (I only have fweight in my dataset) to this code?

    egen pc_immig = mean(100 * inlist(immig, 1, 2)), by(prov)

    egen tag = tag(prov)

    twoway bar pc_immig prov if tag & inlist(prov, 10, 11, 12, 13) || scatter pc_immig prov if tag & inlist(prov, 10, 11, 12, 13), mlabel(pc_immig) msym(none) mlabpos(12) ||, xla(10/13, valuelabel) ytitle(% of immigrants)

  • #2
    A weighted mean can always be calculated as SUM (weight * whatever) / SUM (weight) and you'd need to do that before firing up the graph command.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      A weighted mean can always be calculated as SUM (weight * whatever) / SUM (weight) and you'd need to do that before firing up the graph command.
      Thank you for your reply Nick. I also want to know if it is possible to combine two codes in inlist function?
      For example, I currently have four provinces in my inlist function (10,11,12,13), and I want to combine two of them in only one bar. Is that possible?

      Thank you

      Comment

      Working...
      X