Stata FAQ
How can I test for a trend across a categorical variable?

In a oneway analysis of variance (ANOVA), the alternative hypothesis is that the means across the levels of a factor variable are not equal. In the situation where the factor variable has a natural ordering, this alternative hypothesis may not be the exact hypothesis that one wishes to test. An alternative hypothesis is that the responses systematically increase or decrease over the levels of the factor variable. In Stata, the nptrend command performs a non-parametric test of trend for the ranks of across ordered groups. The test is an extension of the Wilcoxon rank-sum test.

For a quick example, we are going to see if there is a trend of ranks of math score over the levels of socio-economic status (ses) using the hsb2 dataset.
use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear
(highschool and beyond (200 cases))

nptrend math, by(ses)

       ses     score       obs      sum of ranks
         1         1        47        3637.5
         2         2        95        9283.5
         3         3        58          7179

          z  =  4.12
  Prob > |z| = 0.000
From the test, there appears to be a trend in math scores across the ordered levels of ses.

How to cite this page

Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.