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: Getting string variable values on graph


From   Eric Booth <[email protected]>
To   [email protected]
Subject   Re: st: Getting string variable values on graph
Date   Wed, 17 Mar 2010 02:25:21 -0500

Jibonayan:

Your description is a bit cryptic, but assuming you want to work with a bar graph, 
here's a couple of approaches to get you started:

**************

clear
inp code  	str20 description 	expenditure 	week

1234		"AppleJuice"		100		1
1234		"AppleJuice"		110		2
1234		"AppleJuice"		120		3
1234		"AppleJuice"		100		4
1234		"AppleJuice"		130		5
1234		"AppleJuice"		140		6
1234		"AppleJuice"		100		7
1234		"AppleJuice"		190		8
2234		"OrangeJuice"		100		1
2234		"OrangeJuice"		110		2
2234		"OrangeJuice"		120		3
2234		"OrangeJuice"		100		4
2234		"OrangeJuice"		130		5
2234		"OrangeJuice"		140		6
2234		"OrangeJuice"		100		7
2234		"OrangeJuice"		100		8
2235		"OtherJuice"		200		1
2235		"OtherJuice"		210		2
2235		"OtherJuice"		120		3
2235		"OtherJuice"		200		4
2235		"OtherJuice"		230		5
2235		"OtherJuice"		240		6
2235		"OtherJuice"		200		7
2235		"OtherJuice"		200		8
end 
**i extended your example a bit to get more products)

tostring week, replace
g week2 = "Week " + week

graph hbar (mean) expenditure, by(week2) over(description) ///
  blabel(bar) name(overview, replace)
graph save overview "overview.gph", replace

//or//

g description2 = "Expenditures on " + description
destring week, replace
levelsof week, loc(num)

foreach v of local num{
   graph hbar (mean) expenditure if week==`v',  ///
   over(description2, label(labsize(v.small)))  blabel(bar) ///
   title(Expenditures for Week `v') name(w`v', replace)
**
graph save w`v'  "w`v'.gph", replace
win man close graph w`v'
}

graph combine w1 w2 w3 w4 w5 w6 w7 w8, xcommon
**though you probably don't want to combine 104 of these**

**************
Some more guidance on exactly what you want to plot & how you want to plot it 
(as well as what commands you've tried) would be helpful.

~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754



On Mar 17, 2010, at 1:41 AM, Jibonayan Raychaudhuri wrote:

> Hi Statalist users,
> 
> I want to generate the time plots of expenditure on 
> 44 products over a period of 104 weeks. My data (hypothetical) 
> look something like this:
> 
> 
> Product Code  	ProductDescription 	Expenditure 	Week
> 
> 1234		AppleJuice		100		1
> 1234		AppleJuice		110		2
> 1234		AppleJuice		120		3
> 1234		AppleJuice		100		4
> 1234		AppleJuice		130		5
> 1234		AppleJuice		140		6
> 1234		AppleJuice		100		7
> 1234		AppleJuice		100		8
> .			.		.		.
> .			.		.		.
> .			.		.		.
> .			.		.		.
> .			.		.		.
> 1234		AppleJuice		100		104
> 2234		OrangeJuice		100		1
> 2234		OrangeJuice		110		2
> 2234		OrangeJuice		120		3
> 2234		OrangeJuice		100		4
> 2234		OrangeJuice		130		5
> 2234		OrangeJuice		140		6
> 2234		OrangeJuice		100		7
> 2234		OrangeJuice		100		8
> .			.		.		.
> .			.		.		.
> .			.		.		.
> .			.		.		.
> .			.		.		.
> 2234		OrangeJuice		100		104
> .			.		.		.
> .			.		.		.
> .			.		.		.
> .			.		.		.
> .			.		.		.
> 
> Product code is numerical and Product Description is  a string
> variable.
> 
> I want to create a graph that would have the Product Description 
> "values" on the Y-axis. That is I want "Expenditure on "Product Description"" on the Y-axis where "Product Description" is "Apple Juice", "Orange Juice" and so on for all 44 products (the final output on 
> the Y-axis would state something like "Expenditure on Orange Juice", 
> for the second graph, for example). 
> 
> I can get a loop to create all the time graphs for 44 products with
> a numerical code like say "Expenditure on Product 2" on the Y-axis but 
> I cannot get "Expenditure on Orange Juice" on the Y-axis. Any ideas as 
> to how to go about getting the string values for the Product Description on the vertical axis of the graph in a loop? 
> 
> Thankyou for your help.
> 
> Jibonayan
> 
> 
> 
> 
> *
> *   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/






__
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


*
*   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