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

Re: st: renaming a variable from the contents of its observation


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: renaming a variable from the contents of its observation
Date   Thu, 01 Jul 2004 09:52:23 -0400

At 02:36 PM 7/1/2004 +0100,  Dev Vencappa wrote:
Dear all
I have a large data set containing variables v9 to v200.

variable names: v9 v10 v11 v12 v13 v14 ........ ..... v200
Observation 1 TAN TAN TAL TAN CAN TLM
Observation 2 4108 4103 4108 5214 1235 1108

Each of these numbers in the second row of observations represents a particular variable code. What I want is to prefix each of these numbers with the text in the first row of observation e.g. TAN4108 TAN4103 CAN1235 TLM1108, etc. After that, I want to rename my existing variables (v9,v10,v11,...-v126) to these newly created variables.
Presumably these variables are all of string type -- as seen by the contents of the first observation. Thus, even though there are values 4108, 4103, etc. in the 2nd observation, they are really string values. Then you can do this (untested):

forvalues k = 1/200 /* or whatever the maximum is */ {
local newname = v`k'[1] + v`k'[2]
ren v`k' `newname'
}

I hope this helps.
-- David


David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index