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


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

<>

This is what Nick`s proposal would look like in practice:

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

inp int Productcode str30 Productdescription /* 
*/ int(Expenditure Week)
1234		"Apple Juice"		100		1
1234		"Apple Juice"		110		2
1234		"Apple Juice"		120		3
1234		"Apple Juice"		100		4
1234		"Apple Juice"		130		5
1234		"Apple Juice"		140		6
1234		"Apple Juice"		100		7
1234		"Apple Juice"		100		8
2234		"Orange Juice"		100		1
2234		"Orange Juice"		110		2
2234		"Orange Juice"		120		3
2234		"Orange Juice"		100		4
2234		"Orange Juice"		130		5
2234		"Orange Juice"		140		6
2234		"Orange Juice"		100		7
2234		"Orange Juice"		100		8
3334	  "Cranberry Juice"	100		1
3334	  "Cranberry Juice"	110		2
3334	  "Cranberry Juice"	120		3
3334	  "Cranberry Juice"	100		4
3334	  "Cranberry Juice"	130		5
3334	  "Cranberry Juice"	140		6
3334	  "Cranberry Juice"	100		7
3334	  "Cranberry Juice"	100		8
4434		"Lemon Juice"		100		1
4434		"Lemon Juice"		110		2
4434		"Lemon Juice"		120		3
4434		"Lemon Juice"		100		4
4434		"Lemon Juice"		130		5
4434		"Lemon Juice"		140		6
4434		"Lemon Juice"		100		7
4434		"Lemon Juice"		100		8
end

compress
list, noo sepby(Productcode)
gen logexp=log(Expenditure)
gen byte halves=Productcode<3000


//first two products
tw (sc logexp Week, sort) /* 
*/ (lfit logexp Week) if halves ,  /* 
*/ by(Productdescription ,note(""))  /* 
*/ name(firsttwo, replace)

//second two products
tw (sc logexp Week, sort) /* 
*/ (lfit logexp Week) if !halves ,  /* 
*/ by(Productdescription ,note(""))  /* 
*/ name(sectwo, replace)

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


HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Mittwoch, 17. März 2010 14:06
To: [email protected]
Subject: st: RE: RE: RE: Getting string variable values on graph

Naturally in the original problem 44 products may mean more panels than are
wanted on one page. So you could split the graphs into groups using -if-.
Still no loop needed. 

Nick 
[email protected] 

Nick Cox

scatter logexp Week || lfit logexp Week, by(Productde)

seems a simpler way of getting essentially the same graph. You'd want to
decorate that a bit, no doubt. But I see no reason to suppose that a loop is
required here, except in so far as that as what -by()- does on your behalf. 

Nick 
[email protected] 

Martin Weiss

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

Jibonayan Raychaudhuri

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.

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

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


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