Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

RE: st: master labeling file of a string variable


From   Lucie Vlach <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: master labeling file of a string variable
Date   Tue, 26 Jul 2011 10:37:50 -0600

Thank you very much Clyde! I do know the 90 possible values right now.
I will try this! Thank you again!

Lucie

________________________________________
From: [email protected] [[email protected]] On Behalf Of Clyde Schechter [[email protected]]
Sent: July 26, 2011 8:37 AM
To: [email protected]
Subject: RE: st: master labeling file of a string variable

If this is a one-off situation for this variable, and if you know in
advance all 90 possible values, the simplest thing would be to write a do
file which does nothing other than define the HSC_num label, and save it
in the directory where you are working with these files (say you call the
file HSC_label.do).  Then in any other do-file that uses any of these data
sets, as soon as you bring in the Health_Service_Code variable:

run HSC_label
encode Health_Service_Code, gen(HSC_num) label(HSC_num)

(You could -do- it instead of running it if you want to see a listing of
the full label.)

If you don't know all 90 possible values at this time, or if there are
other reasons for not doing it this way, you can do it on the fly as
follows:

In the first do-file that encounters Health_Service_Code:

encode Health_Service_Code, gen(HSC_num) label(HSC_num)
label save HSC_num using HSC_label, replace

This will create and save as much of the HSC_num label as can be
constructed from the data in that file.

In all subsequent files where you encounter Health_Service_Code, the first
thing you should do is:

run HSC_label   // OR do HSC_label IF YOU WANT TO SEE THE LABEL
encode Health_Service_Code, gen(HSC_num) label(HSC_num)
label save HSC_num using HSC_label, replace

-encode- will use the earlier version of HSC_num to the extent it covers
the data and will then assign new consecutive numerical values to new
values of Health_Service_Code and modify HSC_num accordingly.  That
modified label is now safely saved and ready to use when the next batch of
data comes along.


Clyde Schechter
Department of Family & Social Medicine
Albert Einstein College of Medicine
Bronx, NY, USA


*
*   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/

This message and any attached documents are only for the use of the intended recipient(s), are confidential and may contain privileged information. Any unauthorized review, use, retransmission, or other disclosure is strictly prohibited. If you have received this message in error, please notify the sender immediately, and then delete the original message. Thank you.

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index