Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: overlaid graphics


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: overlaid graphics
Date   Mon, 16 Feb 2004 11:29:35 -0000

It seems to me you don't want to overlay 
two time series as such. You just want two 
scales, one a multiple of the other. Here's 
another way to do that. 

Let's read in some time series data 

. use http://www.stata-press.com/data/r7/grunfeld.dta, clear

If I pick a time series 

. twoway connect mvalue year if company == 1

and I also find out its initial value of 3078.5, I can 
then use a utility -mylabels- from SSC which is designed for 
these problems:  

* you want to show labels on one scale, but 

* the graph is working with values on another scale. 

In this case, values range from just below to almost
twice the initial value. I decide on a base of 100
and index values 80 100 120 140 160 180, whereas 
the graph is working with values which are those
multiplied by 3078.5/100. That is, 

	label I want   scale used by -graph- 
	------------------------------------
	80             80 * 3078.5 / 100
	100            100 * 3078.5 / 100
	etc. 

I put the desired labelling information in 
a local macro: 

. mylabels 80(20)180 , myscale(@ * 3078.5 / 100) 
	local(labels) 

-mylabels- echoes the macro, so I can see when 
I'm on the right track: 

2462.8 "80" 3078.5 "100" 3694.2 "120" 4309.9 "140" 4925.6 "160" 5541.3 "180"

A suitable graph is then something like 

. twoway connect mvalue year if company ==1 , 
	yaxis(1 2) 
	yla(3000(500)6000, ang(h) axis(1))   
	yla(`labels', ang(h) axis(2)) 
	yli(3078.5, axis(2)) 
	ytitle(initial value = 100, axis(2)) 

If you just want fractions, then the call is 
clearly 

. mylabels 0.8(0.2)1.8 , myscale(@ * 3078.5) 
	local(labels) 


Nick 
n.j.cox@durham.ac.uk 

John D. Levendis
> 
> I've got a question regarding how to overlay two time series.
> 
> Let say I've got a Price Series (Pr) and from it, I generate 
> a Price Index (PI) 
> that just divides Pr by it's base year value:
> . gen PI = Pr/Pr[1]
> 
> Appropriately scaled these two series, when overlaid should 
> match up perfectly.
> What I would like to do is graph both these series, and if I 
> look at the units 
> on the left hand side of the graph, I get the Price values, 
> and if I look at 
> the units on the right hand side, I get the Index values.
> 
> I thought something like:
> . twoway (connected Pr year) (connected PI year, yaxis(2))
> 
> But they don't line up exactly. How can I force them to?
> 
> This problem holds even in the simpler case where:
> . gen Pr2 = Pr + 100
> . twoway (connected Pr year) (connected Pr2 year, yaxis(2))

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index