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]

st: RE: match variable across two tables


From   "Sarah Edgington" <sedging@ucla.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: match variable across two tables
Date   Wed, 18 Dec 2013 12:05:45 -0800

Rochelle,
This looks like it may be a pretty complicated problem.  I don't immediately have any suggestions because I'm not sure I understand either the exact structure of your data or the matching rules you want to follow.

You say that if you use exact matching that you want I-O number 1111B0 to match with NAICS code 111150.  I take it that is an "exact match" because you want to drop the trailing zero in the NAICS code.  So, since 11115 appears in the list of NAICS codes for 1111B0, it would match to 111150 in table 2.  This is not to my mind an "exact match" because it requires first modifying the NAICS code in table 2 before you can match.  To do that successfully you need to be very clear about what the rule for modification is.
Is the rule that if the NAICS code in table 2 has a zero at the end you always drop it?  Does it matter how many digits appear before the zero?

The next question I have is about the structure of table 1 as it appears in Stata.  Do you have a single variable that has multiple codes in it?  If so, you're probably going to have to do some additional processing to that variable before trying to match the two tables.  

The final thing I was unclear on was what you want the final structure of your data to be after matching.  How do you want to deal with entries in table 1 that have multiple matches in table 2?  Do you want the resulting data to contain multiple observations, one for each of the NAICS codes that the I-O number matches to?  

Again for the four digit match, you'll want to be very clear on the rules that make an entry a match.  I'm not sure if you're asking for a match of the first four digits of the NAICS code in table 1 to only the codes in table 2 that are four digits long.  Alternatively perhaps you're looking to match observation in table 1 to ALL the entries in table 2 that share the same first four digits.

If you can more precisely describe the structure of your data as it currently exists, the matching rules you want to follow, and the structure you want your final data to be in, you'll increase your chances of getting a helpful answer from the list.

-S

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Rongrong Zhang
Sent: Wednesday, December 18, 2013 11:15 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: match variable across two tables

Dear STATALISTER,

I have two tables:

Table 1 has 3 variables  I-O number, I-O Name ,   Related 1997 NAICS codes.

Table 2 has 1 variable 1997 NAICS codes.

I want to link these two tables based on NAICS code. However, the
level of details on NAICS code does not match one-to-one because the
tables come from different data source. My goal is to know which NAICS
code correspond to which I-O number. I can’t use Table 1 only, because
TABLE 2 is produced from Wharton Research Database which has company
level financial data – I will use later on.

By different details I mean : e.g.

table 1:

I-O number  I-O Name                  1997 NAICS codes

1110        Crop production

1111A0    Oilseed farming
         11111      11112

1111B0    Grain farming             11113      11114      11115
11116      11119

111200    Vegetable and melon farming
                   1112
111400 Greenhouse and nursery production
                1114
111910 Tobacco farming
                11191
111920 Cotton farming
                11192
1119A0 Sugarcane and sugar beet
      11193 111991
1119B0 All other crop farming
11194 111992 111998

in the above example, I present industry 1110 and its subindustries
1111A0, 1111B0, 111200, each of the subindustries correspond to a few
(or a single) NAICS code (north america industry classification
system).

table 2:
NAICS CODE
111
1111
111150
111199
111219
111310
111320
111332
111334
111335
111339
1114
111411
111419
111421
111422
111920
111930
111940
111998

if I enforce exact match, then table 2  111150 matches with table 1
1111B0,    table 2 1112l9 may be matched with  111200 table 1 I-O.

My question :
1.could you give a sample code/function to do exact match? note, if
first 5digit match, and drop last 0 (naics), we consider that a match
2. if I want to increase match, how could I change the program to do 4
digit match

thanks a bunch,

-- 
Best,
Rochelle

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index