Announcement

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

  • Line graph scale

    Hi,

    I have created the following graph but need to cut the x-axis at around 500. When I add the code xscale(range(0 500)) to my graph code nothing happens. Any suggestions?
    Additionally, I need to invert cumPSM1 and cumPSM2. What code would I use for this?

    line cumPSM1 cumPSM2 cumPSM3 cumPSM4 price, sort xscale(range(0 500)) ylab(, grid) ytitle("Cummulative Frequency") xlab(, grid) xtitle("Price Level ($)") title("Van Westendorp Price Sensitivity Meter") subtitle("360 participants???")

    Thanks,
    Carmen

    Click image for larger version

Name:	Graph1.jpg
Views:	1
Size:	60.2 KB
ID:	1692320

  • #2
    Code:
    line cumPSM1 cumPSM2 cumPSM3 cumPSM4 price if price <= 500

    Comment


    • #3
      See

      Code:
      help axis scale options
      which explains (emphasis added)

      range() never narrows the scale of an axis or causes data to be omitted from the plot.
      If you wanted to graph yvar versus xvar for the subset of xvar values between 10 and 50, typing

      . scatter yvar xvar, xsc(r(10 50))

      would not suffice. You need to type

      . scatter yvar xvar if xvar>=10 & xvar<=50
      So you could specify if price < 500 or whatever.

      A better solution is to use logarithmic scale. Presumably all prices are positive. It would then be much easier to compare variables.

      I would also reverse the axes and so draw a quantile plot.

      As for "inverting" two variables, does that swapping their position and/or renaming them?

      Pedantically, note that "Cumulative" is correct spelling.


      Comment


      • #4
        This brings together suggestions in #3

        Use log scale.

        Use quantile plots, not cumulative distribution plots.

        And adds another: When different traces on a graph would be hopelessly tangled and hard to tell apart, use what has been called a front-and-back plot: Plot each subset in turn, with all the other subsets as backdrop. The name of the plot is fairly new, but the idea isn't.

        See https://dro.dur.ac.uk/33697/1/33697.pdf

        and if extra context is sought https://www.stata-journal.com/articl...article=gr0080 (which will emerge from behind a paywall in a few weeks' time) or https://journals.sagepub.com/doi/pdf...867X1101000408

        Here I apply the recipe for quantile plots for 4 subsets for which log scale helps. fabplot must be downloaded following

        Code:
        net sj 21-2 gr0087

        Code:
        webuse grunfeld, clear
        
        bysort company (invest) : gen pp = (_n - 0.5) / _N
        
        set scheme s1color 
        
        fabplot scatter invest pp if company <= 4, by(company) ysc(log) frontopts(recast(connect) lcolor(blue)) yla(50 100 200 500 1000 2000, ang(h)) xla(0 1 0.25 "0.25" 0.5 "0.5" 0.75 "0.75") xtitle(Cumulative probability)

        Now we are free of the back and forth between legend and graph. Which colour is PSM3? This colour is which variable?

        Click image for larger version

Name:	fabplot5.png
Views:	1
Size:	51.4 KB
ID:	1692339


        You would need to reshape long with your dataset before doing this.

        Comment


        • #5
          Click image for larger version

Name:	Screen Shot 2022-12-09 at 16.48.26.png
Views:	3
Size:	52.8 KB
ID:	1692785
          Amazing! The code worked. Thank you very much.

          I would have another question for a new graph I am trying to replicate (above).




          I need to plot the aggregate demand curves for three variables on the same graph (see image above for reference)
          The curves should show the aggregate demand based on aggregating individuals' responses to the OE, DC, or BDM questions.
          Here quantity should be the aggregate demand that is normalized to a range between 0 and 1 due to differing sample sizes.

          Could somebody provide me some guidance on how to do this in stata? I am somewhat new to the program and would appreciate any help.

          Thanks,
          Carmen
          Last edited by carmen campagnolo; 09 Dec 2022, 13:05.

          Comment


          • #6
            I would start a new thread for #5. Unfortunately, answers are likely to be very limited without an idea and example of your data structure and content.

            Comment

            Working...
            X