Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Use of local macros when generating new variables (-rowranks-)

From   Michael Crain <>
Subject   st: Use of local macros when generating new variables (-rowranks-)
Date   Thu, 23 May 2013 11:27:20 -0700 (PDT)

Using Nick Cox's -rowranks- ado that ranks values across rows, the
general syntax is:
rowranks x1-x5, generate(r1-r5)

My very large dataset consists of subsets of rows (variables) that I
want to rank. I need some help on the syntax (or approach).

My variables have this general form: C[code string]_[time period]

I want to rank across the C[code string] variables by _year_. For
instance, my variables look like this:


I want to rank across Cabc Cdef C456 C789 for each time period so:
a. rank across Cabc_1 Cdef_1 C456_1 C789_1, then
b. rank across Cabc_2 Cdef_2 C456_2 C789_2, then 
c. rank across Cabc_3 Cdef_3 C456_3 C789_3

I tried using a loop but my problem is how to write the -rowranks-
syntax for the subset variable range for the source variables and new
rank variables.

My loop is this:

levelsof timedummy, local(timeperiod)
levelsof codestring, local(code)
foreach t of local timeperiod {
   foreach c of local code {
      rowranks C`c'_`t', gen(R`c'_`t')

With this code, Stata sees my source variables (over 200 of them in year time period), but sees only one new variable name (an error). I tried variations of this syntax for the variables with no success,

Can anyone help with the syntax? Or is there is a better approach?

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index