Statalist


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

st: Re: Looping with label define


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: Re: Looping with label define
Date   Thu, 19 Feb 2009 20:39:00 +0100

<>

Just ditch the macro thing altogether

*********
clear
input str20 county countynumber
Andrews 1
Anderson 2
Austin 3
Bexar 5 Childress 4
Denton 6
end


forvalues num = 1/6 {
label define lab `num' "`=county[`num']'", modify
}

label val countynumber lab
************


HTH
Martin _______________________ ----- Original Message ----- From: "Eric A. Booth" <[email protected]>
To: <[email protected]>
Sent: Thursday, February 19, 2009 8:17 PM
Subject: st: Looping with label define


Hello:

I am trying to define labels for a numeric variable (countynumber) using an existing string variable (county) so that the the countynumber will take on a value label equal to the county for that same row.

I would like to use looping with the "label define" command to complete this task. (I've been successful with using looping with the encode and replace commands to get this to work (after sorting the data), but my dataset has many variables (sorted in several different ways) that will get the same set of value labels & minor tweaks to the these value labels may occur frequently and so I'd like to be able to make those changes to one column and then apply it to all the associated variables in my dataset)

An example of what I've tried is below. When I run this code, it applies "Andrews" as the value label for all of the values in countynumber.

___________________________

clear
input str20 county countynumber
Andrews 1
Anderson 2
Austin 3
Bexar 5 Childress 4
Denton 6
end

local testmacro = county[_n]

forvalues num = 1/6 {
label define lab `num' "`testmacro'", modify
}

label val countynumber lab

___________________________

Thanks for any help!


Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
Fax: +979.845.0249
http://ppri.tamu.edu


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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