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

Re: st: RE: RE: Counting unique values across a set of variables: Re-sent


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: RE: RE: Counting unique values across a set of variables: Re-sent
Date   Mon, 24 May 2004 15:51:08 -0400

you forgot the word varlist in the foreach...

foreach v of var1-var10 {;

should be:

foreach v of varlist var1-var10 {;

Michael Blasnik
michael.blasnik@verizon.net

p.s. The answer to your second question is yes -- it will subtract one when
countperiod is greater than zero (or missing)


----- Original Message ----- 
From: "CM" <cmhsieh54@yahoo.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Monday, May 24, 2004 2:33 PM
Subject: Re: st: RE: RE: Counting unique values across a set of variables:
Re-sent


> Nick,
>
> 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?
>
> best,
> cm
>
> -------------------
> 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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index