Announcement

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

  • Adding IQR to trajectory line plot based on WIDE format data

    Dear experts,

    The Profileplot command can display the trajectory line based on median.

    profileplot variable1_time1 variable1_time2 variable1_time3, median



    Q1 Can we add IQR Bar (Interquartile Range) to the plot using the same profileplot command?


    Q2 Is that any other command that can display the trajectory line using medians with IQR Bar from WIDE format data without reshaping it to long format data?

    Thank you and looking forwards to any solution.
    Last edited by Anthony Jones; 24 Jan 2021, 20:41.

  • #2
    Q1 No such option

    Q2 Not that I know of.

    There can occasionally be reasons for holding e.g. repeated measures in wide layout, but for most Stata purposes long layout is greatly preferable. For one, this kind of plot is immediately accessible using egen to calculate summary statistics and twoway to plot them.

    Support for this position is that
    profileplot (from the UCLA website, as you are asked to explain) temporarily reshapes the dataset to long before it draws a graph!

    Comment


    • #3
      However -- the example dataset behind profileplot is not one where a long layout is especially helpful.

      You can draw your own profiles for just about any common summary measure with a
      collapse followed by a graph call. Here is an example. Using a loop to write code for each variable and each measure is not obligatory as you can always write the collapse syntax directly (here for 3 variables and 3 measures, so 9 new variables).

      Code:
      use https://stats.idre.ucla.edu/stat/stata/notes/hsb2, clear
      
      local call
      
      foreach v in read write math {
          local call `call' (median) `v'_p50=`v' (p25) `v'_p25=`v'  (p75) `v'_p75=`v'
      }
      
      collapse `call', by(race)
      
      line read_* race

      That said, using lines to connect different categories is at best cosmetic and at worst hard to defend. And median and quartiles are shown by any boxplot command, or optionally with
      dotplot or optionally with stripplot (SSC), or indirectly on quantile plots.


      Here is a sample quantile plot for three scores and four races. The median and quartiles are naturally tacit -- and much more detail is conveyed than in a bare box plot.

      qplot is from the Stata Journal.


      Code:
      use https://stats.idre.ucla.edu/stat/stata/notes/hsb2, clear
      stack read race write race math race, into(score race) clear
      label def _stack 1 read 2 write 3 math
      label val _stack _stack
      label def race 1 Hispanic 2 Asian 3 "African-American" 4 white
      label val race race
      
      qplot score, over(race) by(_stack,  row(1) note("")) scheme(s1color) legend(row(1)) xla(0 0.25 0.5 0.75 1) yla(30(10)80)
      Code:
      
      


      Click image for larger version

Name:	qplot_ucla_race.png
Views:	1
Size:	58.4 KB
ID:	1591195
      Last edited by Nick Cox; 25 Jan 2021, 07:13.

      Comment

      Working...
      X