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, **statalist.org** is already up and running.

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

From |
Michael Crain <michaelcrain@ymail.com> |

To |
statalist@hsphsun2.harvard.edu |

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: Cabc_1 Cdef_1 C456_1 C789_1 Cabc_2 Cdef_2 C456_2 C789_2 Cabc_3 Cdef_3 C456_3 C789_3 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: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: Use of local macros when generating new variables (-rowranks-)***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: Observations that keep a feature...** - Next by Date:
**Re: st: Need to Split String Variable** - Previous by thread:
**st: Need to Split String Variable** - Next by thread:
**Re: st: Use of local macros when generating new variables (-rowranks-)** - Index(es):