Statalist


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

st: creating an ordered month variable over several years


From   Michael McCulloch <[email protected]>
To   Statalist Statalist <[email protected]>
Subject   st: creating an ordered month variable over several years
Date   Wed, 25 Nov 2009 18:03:17 -0800

Hello Statalist friends,
I'd appreciate any feedback on this question: I'd like to create a variable m_y, which I can sort in order of month over several years.

I've simulated data with:
. clear
. set obs 100
. gen id=_n		// subject id
. gen month=1 + int(12*uniform())
. gen year=2008 + int(2*uniform())
. gen subject_type=1 + int(3*uniform())
. la def lab_subjects 1 "no reply" 2 "screened" 3 "sampled", modify
. la val subject_type lab_subjects
. list, noo

But, I'd like guidance on how to combine month and year into one ordered variable, to appear with labels such as:
	Jan 2008
	Feb 2008
	...
	Jan 2009
	Feb 2009

That ordered variable would then be displayed in the -by(month)- option in this graph:
	. catplot bar subject_type, by(month) stack asyvars ///
		bar(1, bcolor(red)) 	///
		bar(2, bcolor(yellow))  ///
		bar(3, bcolor(green))

I could use both -over- and -by-, but that looks awkward:
	. catplot bar subject_type, by(year) over(month) stack asyvars ///
		bar(1, bcolor(red)) 	///
		bar(2, bcolor(yellow))  ///
		bar(3, bcolor(green))



Best wishes,

Michael McCulloch
Pine Street Foundation
124 Pine Street
San Anselmo, CA 94960-2674
tel:	415-407-1357
fax: 	206-338-2391


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index