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

st: RE: RE: Re: Programming help


From   "Dr. Martyn Sherriff" <martyn.sherriff@kcl.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Re: Programming help
Date   Tue, 12 Aug 2003 12:02:49 +0100

As ever many thanks for your assistance. For each value of code there are 7
values of id and I was attempting to produce an output listing the integral,
id and associated code.
Martyn

Youth Rugby: www.fullerians.demon.co.uk

"The difference between winners and losers is that winners tell the jokes
and the losers talk about the run of the ball." 
 

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 12 August 2003 11:41
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: Re: Programming help


Dr. Martyn Sherriff
 
> This loops correctly over i, but in the data set the
> variable code takes the
> values 96,137(1). I need to print out the code for 
> reference only but it
> does not change from the initial value if 96. What should I 
> do to modify the
> program? Can I write the "displayed" variables directly to 
> an output file?
> 
> set more off
> forvalues i=1/294{
> 		integ volume rtime if id==`i', gen(Sv)
> 		display  code  `i'  "   r(integral)
> 		drop Sv
> }
> set more on

I am not sure I understand what you want but 

. display code `i' 

will always be interpreted as if you 
were saying 

. display code[1] `i' 

In essence, the -display- statement has no 
way of knowing that you consider a particular 
value of -code- to be the current value. -display- 
arbitrarily choose the first value of a variable 
if none is specified. 

What's more, there will be no 
space between the two items printed. 

It sounds as if you want something more 
like 

forval i = 1/294 { 
	qui integ volume rtime if id == `i' 
	display code[`i'] " " r(integral)
} 

where I have omitted generating an optional 
variable only to -drop- it a moment later. 

If you shut up -integ-, you can just 
collate the results within a log. There
are other ways to do it, e.g. -file-.

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

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


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