Statalist


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

AW: st: RE: AW: creating an ordered month variable over several years


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: RE: AW: creating an ordered month variable over several years
Date   Thu, 26 Nov 2009 16:46:10 +0100

<> 

" sc sampled screened noreply m"



This command alerts me to the fact that you can supply a -varlist- to
-scatter-, with all but the last variable interpreted as y-variables. The
help file does discuss this issue under the heading "Scatter syntax", but
would I be able to tell from the drop-downs in the dialog box that this is
possible? It only accepts a single y-variable...


HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Austin Nichols
Gesendet: Donnerstag, 26. November 2009 16:34
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: RE: AW: creating an ordered month variable over several
years

A pair of alternative approaches, for side-by-side or stacked bars:

clear all
set seed 1
set obs 1000
gen id=_n
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
g m=(year-1960)*12+month-1
format m %tmm_CY
la var m "Calendar month"
levelsof m, loc(vs)
foreach v of loc vs {
 la def m `v' "`:di `:format m' `v''", modify
 }
la val m m
ssc inst byhist, replace
byhist m, by(subject_type) disc tw(xla(576/599,angle(90) val))
contract m subject_type, z f(one)
reshape wide one, j(subject_type) i(m)
g noreply=max(0,one1)
g screened=max(0,one1)+max(0,one2)
g sampled=max(0,one1)+max(0,one2)+max(0,one3)
sc sampled screened noreply m, recast(bar) xla(576/599,angle(90)) name(s)


On Thu, Nov 26, 2009 at 6:00 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> Note that the alternative approach of assigning a date format to a
> monthly date variable doesn't seem to help enough.
>
> gen mydate = ym(year, month)
> format mydate %tmm_CY
>
> followed by a graph with -by(mydate)- just uses the numbers and not the
> format. Mapping that to a string causes display in alphabetical order
> (all Aprils first) which is unlikely to be helpful.
>
> -catplot- is a user-written command from SSC, but is not causing this
> behaviour. -graph bar, by()- is responsible.
>
> Perhaps there is a work-around.
>
> Nick
> n.j.cox@durham.ac.uk
>
> Martin Weiss
>
> *************
> 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
>
> compress
>
> //from http://www.stata-journal.com/sjpdf.html?articlenum=pr0013
> //follow special sequences
>
> //generate label for months
> tokenize `c(Months)'
>
> forvalues i = 1/12 {
>  label def month `i' "``i''" , modify
>  }
>
> label val month month
>
> decode month, generate(mon)
> gen yearmonth=  mon + " " + string(year)
>
> catplot bar subject_type, by(yearmonth) stack asyvars ///
>                bar(1, bcolor(red))     ///
>                bar(2, bcolor(yellow))  ///
>                bar(3, bcolor(green))
> *************
>
> Michael McCulloch
>
> 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))
>

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