Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: quantiles


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: quantiles
Date   Tue, 9 Nov 2010 21:33:11 +0000

<>


Based on your description, I'm not sure why you are getting a blank plot, but first realize that you aren't asking Stata to plot the quantile information together in one plot, instead you are asking it to plot the p50 for all 1000 people and then the p75 for all 1000 people and so on with your loop:

> 
> local stats ="mean p50 p75 p90"
> foreach p of local stats {
> graph bar (`p') person1-person1000, over(date)
> graph export "quantile_`p'.png", replace
> }



If this is really what you want, this does *work* for me in the code below (but I only run it for 10 people because 1000 would make the graph unreadable):


****************!
clear
set obs 15  //fake data uses 15 dates//

**create fake dates**
g date = 17000+int((801)*runiform())
duplicates drop
sort date
format date %td

**create fake scores**
forval n = 1/1000 {
g person`n' = int((101)*runiform())
}

tostring date, g(date2) force u
local stats ="mean p50 p75 p90"
foreach p of local stats {
 graph bar (`p') person1-person10, over(date2, sort(date))
*graph export "quantile_`p'.png", replace
}
****************!


I don't think this is a good idea.  
Instead, you could -egen- the quantile information you describe across the row and then plot that using a series of bar charts, or put it all in one bar chart, like this:

****************!
**continuing using the data generated above**

//egen quantile information//
egen avg = rowmean(person1-person1000)
foreach n in  25 50 75 90 {
egen p`n' = rowpctile(person1-person1000), p(`n')
}

//plot separately//
foreach p in avg p25 p50 p75 p90 {
	 graph bar `p' , over(date2, sort(date)) blabel(total) ///
	 title(`p')
}

//or plot together//

graph bar avg p25 p50 p75 p90, over(date2, sort(date))
***************!



or you could plot it as lines all in one graph:

****************!
**twoway line plot over time**
twoway (connected avg date, sort mlabel(avg) ///
lpattern(dash)  mlabsize(medsmall) mlabposition(12) mlabgap(small)) ///
 (connected p25 date, msize(tiny) mlabel(p25) ///
 lcolor(blue)  msymbol(square) lwidth(medium)  ///
 lpattern(solid)  mlabsize(medsmall) mlabposition(12) mlabgap(small)) ///
 (connected p75 date, msize(tiny) mlabel(p75) ///
 lcolor(blue)  msymbol(square) lwidth(medium) ///
  lpattern(solid)  mlabsize(medsmall) ///
   mlabposition(12) mlabgap(small)) ///
 (connected p90 date, msize(tiny) msymbol(circle) ///
  mlabel(p90) lwidth(thin) lpattern(dot)  ///
  mlabsize(medsmall) mlabposition(12) mlabgap(small)) ///
 (connected p50 date, msize(tiny) lpattern(solid) ///
 lcolor(red) lwidth(medsmall) )  , ylabel(#5) legend(on rows(1) span)
****************!

Watch for wrapping issues in the code above.  If this isn't what you want, it's probably a good idea to give us a better explanation of what you'd like to graph.


- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
Fax: +979.845.0249
http://ppri.tamu.edu




On Nov 9, 2010, at 2:25 PM, Benodet Karia wrote:

> Dear Statalisters,
> 
> My question sounds basic but I couldn't find a way out. 
> 
> I  have a date column and beside it I have 1000 columns, each column denotes the grade of a corresponding person at the given date. Let's say the date goes from d1 to d100.
> 
> What I want to do is to plot a diagram for the quantiles (preferably deciles) given the specific date intervals, say for d1-d100 or d20-d30. 
> 
> Thus on the graph, I should have date on the x-axis and the scores on the y axis. And the graph should show the performance in terms of quantiles. 
> 
> I tried the following however it doesn't seem to work:
> 
> local stats ="mean p50 p75 p90"
> foreach p of local stats {
> graph bar (`p') person1-person1000, over(date)
> graph export "quantile_`p'.png", replace
> }
> 
> When I ran the code, as expected, I got 4 plots for each quantile but they don't show anything. I think the part where I wrote person1-person1000 is false?? Can you recommend how I can change my code?
> 
> Any help will be greatly appreciated. Thank you in advance.
> 
> b. 		 	   		  
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index