Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: A problem with append


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: A problem with append
Date   Tue, 26 Sep 2006 14:03:32 +0900

Silvia Mendolia wrote:

I am working with two different files, containing labour force status.
In the first one the status is coded as follows:
Looking after family: 5
FT Education: 6
Long term sick: 7
Maternity leave: 8

In the second one it is:

Maternity leave:5
Looking after family: 6
FT education: 7
Long Term sick: 8

So, if I try to append the first one under the second one, people looking
after family are recorded as maternity leave, people in FT education are
recorded
as looking after family and so on...

How can I change the code of the labour force status in one of the two
files?

--------------------------------------------------------------------------------

You can use -recode- to change the numbers in one of the two datasets before
appending.  If these numbers are associated with value labels, then you'll
want to take care about which set of label values you retain after
appending.

If you choose to change the code in the second dataset, and if you're using
value labels, then the syntax might look something like:

tempfile tmpfil0
use file2, clear
_strip_labels labour_force_status
label drop LabourForceStatus  // Assumes that file1's value labels are
                                               // all-inclusive
recode labour_force_status (5 = 8) (6 = 5) (7 = 6) (8 = 7)
save `tmpfil0'
use file1
append using `tmpfil0', nolabel // Be careful with this option
erase `tmpfil0'

I'm not sure whether a couple of the lines above are really necessary (or
even detrimental), but they might just help assuage you that the first
dataset's value labels will rule the day.  Exercise caution that there
aren't variables with values (and their corresponding value labels) in the
second dataset that don't exist in the first.

If you're not using value labels, then the syntax might look something like:

use file2, clear
recode labour_force_status (5 = 8) (6 = 5) (7 = 6) (8 = 7)
append using file1

If you're concerned about being unable to avoid getting value labels mixed
up or about values getting accidentally orphaned from their value labels,
then use -decode-, -append- and then -encode-.  If you're doing a lot of
mixed-source compilation (even longitudinal surveys change their coding
every so often), then this is probably the best way.

Joseph Coveney


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