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

Re: st: Re: looping and replacing values


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Re: looping and replacing values
Date   Fri, 1 Aug 2003 16:44:10 -0400

No it doesn't require the observation to be the first one.

The command includes bysort farmid (`var'), which will sort the sinlge
non-missing observation to always be first in each panel for each var.

Michael Blasnik
michael.blasnik@verizon.net

----- Original Message ----- 
From: "Buzz Burhans" <wsb2@cornell.edu>
To: <statalist@hsphsun2.harvard.edu>
Sent: Friday, August 01, 2003 4:39 PM
Subject: Re: st: Re: looping and replacing values


> Thanks Michael
>
> That is close, and I am about to try it, (trying to get a project finished
> before the weekend, so I really appreciate your timely help).
>
> Anyway, it looks like your code would require the single obs for each
panel
> to be the first one ??: {1},
> and it is not necessarily there, sometimes it is the 7th, sometimes the
10th...
>
> I am going to try this now.
>
> Thanks again
>
> Buzz Burhans
> wsb2@cornell.edu
>
>
> At 04:23 PM 8/1/03 -0400, you wrote:
> >How about:
> >
> >foreach var of local Varts {
> >bysort farmid (`var'): replace `var'=`var'[1]
> >}
> >
> >Michael Blasnik
> >michael.blasnik@verizon.net
> >
> >----- Original Message -----
> >From: "Buzz Burhans" <wsb2@cornell.edu>
> >To: <statalist@hsphsun2.harvard.edu>
> >Sent: Friday, August 01, 2003 4:00 PM
> >Subject: st: looping and replacing values
> >
> >
> > > I wonder if someone could help me with the syntax below.
> > >
> > > I have panel data, long form, which has variables where only one
> > > observation contains a value within each panel, and the other
observations
> > > for that panel and variable are missing
> > >
> > > I would like to loop over the panels and the variables and replace the
> > > missings for each panel/variable with the single existing observation
for
> > > that panel that has a value. I used min, but it doesnt really matter
if it
> > > is min etc, as there is only one value extant for each panel.
> > >
> > > There are however, a lot more variables than I show here, and I am
quite
> > > unsuccesful at making the foreach loops work right.
> > >
> > > My attempts look like this, and I would appreciate any help.
> > >
> > > Thanks
> > >
> > > local Varts "CostCowM7toM12 CostCowQtr CostCWTYrly CostCWTM1toM6
> > > CostCWTM7toM12 CostCWTQtr "
> > > tokenize `Varts'
> > > levels farmid, local(levels)
> > > foreach l of local levels {
> > >
> > > syntax [varlist]
> > > foreach var of local Varts{
> > > replace `var' = min(`var')
> > >
> > > }
> > > }
> > >
> > >
> > > Buzz Burhans
> > > wsb2@cornell.edu
> > >
> > >
> > > *
> > > *   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/
>
>
> *
> *   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