# st: RE: RE: percentage for each month plotted vs. month

 From "Nick Cox" <[email protected]> To <[email protected]> Subject st: RE: RE: percentage for each month plotted vs. month Date Mon, 2 May 2005 15:45:20 +0100

```In practice, this would lead to lots of overplotting.
Leaner graph files would ensue from

gen month = month(date)
egen adult_x = mean(100 * (2 - x)) if adult == 1, by(month)
egen child_x = mean(100 * (2 - x)) if adult == 2, by(month)
bysort month (child_x) : replace child_x = child_x[1] if mi(child_x)
egen tag = tag(month)
line *_x month if tag

Nick
[email protected]

Nick Cox

> I assume variables
>
> date: Stata daily date
> x: as defined below
>
> You can get months by
>
> gen month = month(date)
>
> The percent of drug use would then be
>
> egen adult_x = mean(100 * (2 - x)) if adult == 1, by(month)
>
> egen child_x = mean(100 * (2 - x)) if adult == 2, by(month)
>
> The graph would be
>
> line *_x month
>
> To cycle over many months,
>
> foreach v of var x y z a b c d e f {
> 	egen adult_`v' = mean(100 * (2 - `v')) if adult == 1, by(month)
> 	egen child_`v = mean(100 * (2 - `v')) if adult == 2, by(month)
> 	line *_`v' month, saving(`v')
> 	more
> }
>
> Note how binary coding 1 for use, 0 for no use, would lead
> to cleaner formulae.
>
> Nick
> [email protected]
>
> [email protected]
>
> > I have the following survey data of 1000 patients collected over 15
> > months:
> >
> > Each observation contains the following variables:
> > X:  "1" for using drug x and "2" for not using drug x
> > DATE: Day and month patient was enrolled in study (variable
> > DATE as day
> > month year)
> > Adult: "1" yes "2" no
> >
> > I would like to plot the percentage of patients who were
> > using drug x in a
> > given month  vs. month & year. So the axes would be Y: "percent of
> > patients using drug x in given month" and X axis: "month & year of
> > enrollment"
> >
> > I cannot seem to figure out an easy way to do this.  It seems
> > that I have
> > to generate many variables to get a simple percentage of
> > patients who were
> > using drug x for that particular month and then to plot it.
> >
> > Also, I would like to get more sophisticated as well: the
> > same graph as
> > above but have two lines on one graph; one line would
> > represent the data
> > for children and the other for adults.
> >
> > Also, I'd like to generate many graphs using the do editor
> > (same as above
> > for other drugs).  When I try using the do editor this, I get
> > one graph
> > and then the next is shown and I get to save only the last.
> > Is there a
> > way I could run several graphs using the do editor and then
> > save them all
> > so that I could view them leisurely?
> >

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