Thanks to Michael for fielding this.
On the second question, see also
http://www.stata.com/support/faqs/data/trueorfalse.html
Nick
n.j.cox@durham.ac.uk
Michael Blasnik
>
> you forgot the word varlist in the foreach...
>
> foreach v of var1-var10 {;
>
> should be:
>
> foreach v of varlist var1-var10 {;
>
> p.s. The answer to your second question is yes -- it will
> subtract one when
> countperiod is greater than zero (or missing)
CM
> > Thanks, I'm going with your first method with
> > reshape's. When I get to the line below marked
> > "********" I get an r(198) syntax error. What do I
> > have incorrect (I thought I had the semi-colons in the
> > right places)?
> >
> > And with the last line where "countperiod > 0", that
> > will only subtract Z by 1 when the condition is met?
> >
> > -------------------
> > use c:\temp\Book1 ;
> >
> > reshape long var , i(id) j(num) string ;
> >
> > bysort id var : gen Z = _n == 1 ;
> > by id : replace Z = sum(Z) ;
> > by id : replace Z = Z[_N] ;
> >
> > reshape wide var , i(id) j(num) string ;
> >
> > gen countperiod = 0 ;
> > foreach v of var1-var10 { ;
> > replace countperiod = countperiod + (`v' == ".") ;
> > } ; ********
> >
> > replace Z = Z - (countperiod > 0) ;
*
* 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/