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 at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: master labeling file of a string variable


From   "Clyde Schechter" <clyde.schechter@einstein.yu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   RE: st: master labeling file of a string variable
Date   Tue, 26 Jul 2011 07:37:03 -0700

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/


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