Announcement

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

  • Marker size with [pw=weight] in twoway tsline

    In the following code the markers become very large. I would like to weight the data but not have the markers change size. Does anyone know how I can do this please?
    Code:
     
    (tsline `giipp'  if `ByVar1'==1 & `ByVar2'==1 & $yearrange [pw=$WEIGHT], msymbol(`symbolMale')   lpattern(`lineMale')   color($colour1) recast(connected))
    (the code works otherwise (ie without the weights I get what I expect - I have not given the full code or data as I'm pretty sure you will not need it).
    Thanks
    Laurence


  • #2
    Originally posted by Laurence Lester View Post
    I would like to weight the data but not have the markers change size.
    That does not make sense. The individual weights determine the sizes of the markers. If you want to constrain the marker sizes, create a categorical weight variable by grouping the values of your weight variable and use the categorical variable instead. Otherwise, if you want all markers to have the same size, you don't need a weight variable—simply specify the desired marker size in the standard scatter plot.

    Code:
    sysuse auto, clear
    scatter mpg weight, ms(Oh) msize(8)

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	132.9 KB
ID:	1770294

    Comment


    • #3
      Thanks for your reply Andrew Musau but perhaps I was not clear enough. Here is an example of the relevant code without abbreviations and macro
      Code:
      twoway  (tsline IndexOfInterest [pweight=SurveyWeight]),...
      This is for longitudinal survey data, "SurveyWeight" is not a variable in the sense you use Weight from the Auto data - it is the survey weight (so that the data can be weighted to allow inference about the population from which the survey is collected). As far as I can tell, this code weights the data (by the sample weight with [pweight=SurveyWeight] , but it also makes the markers very large.

      I would like to know if there is a way to force twoway (tsline.... to reduce the size of the marker when sample weighting is applied.

      Comment


      • #4
        I believe that Andrew has correctly interpreted what -pweight- stands for, and his comments still stand. Using weights (of any kind) serve one purpose in estimation commands and another in graphics. In estimation, they are to produce the correct type of estimate. In graphs, they are to communicate relative importance/variance of each point (at least in this kind of scatter plot). There is nothing you have explained that should imply weighted marker sizes is particularly important for your graphic.

        If your goal is to simply plot the line/profile, then the weighting is irrelevant and can be omitted. If there is instead some emphasis needed that the weights communicate, you need to construct those weights. If weighting is important, but the default sizes based on -pweights- are too large, how will you alter the weights for graphing purposes only? Andrew has again suggested one way forward, by creating a categorical variable based on the implied weight distribution. Another way could be to take a square root (or some other power) and see what that looks like. There's no right answer here as it is to taste, as long as you explain to the reader exactly what the weights mean.

        Comment


        • #5
          Thank you Leonardo Guizzetti (and Andrew Musau ), My mistake, you have both helped me understand what I am doing and what I thought I was doing (my twoways will be based on a calculate weighted mean). -

          Comment

          Working...
          X