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

Re: st: "for...: graph" question


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   Re: st: "for...: graph" question
Date   Wed, 2 Apr 2003 17:14:34 +0100

Cathy L. Antonakos

> I am printing graphs for temperature data collected at multiple time
> points. One graph for each person in a data file. It's a two way
graph.

> I managed to create one graph per person using

> for num=1001/1011: graph temp order if id==X ... etc.

> However, if the subject id is completely missing from the file,
> the graph still prints (empty) for that person.

> I tried to include "if order~=." after the "graph" command
> (e.g., to skip cases with missing data on one or
> the other variable). It didn't work.

> Is the problem that the case simply doesn't exist in the file,
> so there is no data to operate on to figure out whether a
> variable is missing or not?

> If I embed a blank record within the file for any subject who
> is missing data and who falls within the series from 1001 to 1011,
> will that enable me to override with an "if order~=." statement
> in the "graph" command?

> How would I do this?

> Suggestions welcome. I am a fairly new Stata user, so the simpler
> the suggestion, the better. Thanks.

All Statalist members are asked to state the
version of Stata they are using. Please see
http://www.stata.com/support/statalist/faq/#advice

I guess Stata 7 in your case.

The FAQ at http://www.stata.com/support/faqs/data/for.html
applies. Perhaps the easiest solution for you is

egen group = group(id)
su group, meanonly
forval i = 1/`r(max)' {
	su id if group == `i', meanonly
	graph temp order if group == `i', t1(id is `r(max)')
}

This may look worse than you want -- it is worse
than you want -- but some extras have been written
in.

The -egen- statement creates a variable -group- guaranteed to
have consecutive integers from 1 up as
values. You still need to know the highest
value of -group-, which -summarize- leaves
behind in `r(max)'. In producing
a bundle of these graphs, things can get
very confusing unless each is labelled,
so as an extra step, the -id- for each graph
is shown explicitly.

-for- is a deadend and goes undocumented
in Stata 8, so starting now on -forvalues-
and -foreach- will pay enormous dividends
in your Stata career.

In Stata 8, there is a cleaner solution:

levels id, local(levels)
foreach l of local levels {
	line temp order if id == `l', subtitle(id is `l')
}

once -levels- has been installed from SSC.

You do not need to mess with your data,
at any rate.

Nick
[email protected]

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