# st: chi2 test for linear trend for repeated data

 From BISSERY Alvine To statalist@hsphsun2.harvard.edu Subject st: chi2 test for linear trend for repeated data Date Mon, 02 Jun 2003 09:23:02 +0200

```Dear all,

I'm studing a group of subject with repeated measures in time.
Measurements  are expressed as proportions, and I would like to do a chi2
test to test linear trend for these repeated data ... that means , a kind of
"nptrend" but for repeated data

Does this test exist ?

Thank you

Alvine Bissery
-----Message d'origine-----
De: Scott Merryman [mailto:smerryman@kc.rr.com]
Date: lundi 2 juin 2003 03:07
À: statalist@hsphsun2.harvard.edu
Objet: st: Re: Counting Unique Values by Year

----- Original Message -----
From: "Jennifer S. Earl" <jearl@soc.ucsb.edu>
To: <statalist@hsphsun2.harvard.edu>
Sent: Sunday, June 01, 2003 7:34 PM
Subject: st: Counting Unique Values by Year

> I have a data set with cases spread out over a number of years. I have a
> numeric variable called CLMS. I want to create a new variable UNIQCLMS
that
> equals the number of unique values that CLMS took on each year.
>
> I have thought of some very long-winded ways to do this, such as creating
a
> counter using a lag-comparison and then harvesting the last value of this
> counter, but it seems like it should be easier. In particular, Stata
> already calculates the number of unique values in lots of operations,
> including INSPECT (e.g., "by year: inspect clms" will produce the number
of
> unique values for CLMS, unless that number exceeds 99, but it won't write
> that value out to another variable as far as I know), and the number of
> unique values should also equal the number of rows produced using "by
year:
> tab clms".
>
> So, I am hoping someone might be able to think of a quick and/or elegant
> way to get Stata to produce a new variable, UNIQCLMS that contains the
> number of unique values that CLMS takes on in each year. If I could dream
> up a new egen command, the format would be something like:
>
> by year: egen uniqclm=unique(CLMS)
>
> Any thoughts would be appreciated.
>
> Cheers,
>
> Jennifer
>

Thanks to Nick Cox there is such a command:  -nvals- , part of the egenmore
package will return the number distinct values as a variable.  Something
like:

egen uniqclm = nvals(CLMS) , by(year)

should work.

You also might find the discussion in the FAQ "How do I compute the number
of distinct observations?"

Hope this helps,
Scott

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