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]

st: RE: Getting string variable values on graph


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: Getting string variable values on graph
Date   Wed, 17 Mar 2010 11:18:48 +0100

<>

*************
clear*

inp int Productcode str30 Productdescription /* 
*/ int(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
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
end

compress
list, noo sepby(Productcode)

gen logexp=log(Expenditure)

qui levelsof Productcode

foreach lev in `r(levels)'{
	preserve
	keep if Productcode==`lev'
	tw (sc logexp Week, sort) /* 
*/ (lfit logexp Week),  /* 
	*/ ytitle("Expenditure on `=Productdescription[1]'") /* 
	*/ name(gr`lev', replace) 
	loc grnames `grnames' gr`lev'
	restore
}

gr combine `grnames'
*************


HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jibonayan
Raychaudhuri
Sent: Mittwoch, 17. März 2010 11:10
To: [email protected]
Subject: st: Getting string variable values on graph

Hi Eric,

Thanks a lot for your help. Basically, I run regressions of log(expenditure)
on total week for each of the 44 products and I want to show the scatter for
these two variables with  the regression line in the graph. So, week (1 to
104) is on the horizontal axis and product description is on the vertical
axis. There will be 44 seperate graphs for these products each showing the
time trend for 104 weeks. The expenditures will not be seperately shown for
each week and will also not be shown over the product description as you
have shown in the two cases. I could maybe modify your code to this end.

Jibonayan



--- On Tue, 3/16/10, Jibonayan Raychaudhuri <[email protected]> wrote:

> From: Jibonayan Raychaudhuri <[email protected]>
> Subject: Getting string variable values on graph
> To: [email protected]
> Date: Tuesday, March 16, 2010, 11:41 PM
> 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/


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