Stata.如何匹配1:m关系中的值? [英] Stata. How to match values in 1:m relationship?

查看:1257
本文介绍了Stata.如何匹配1:m关系中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据集.第一个是:

I have two data sets. First one is:

countyGroup income  other_data_
    1       20990   …
    2       25622   …
    3       24289   …
    4       27391   …
    5       23326   …
    6       19261   …
    7       15197   …
    8       11132   …

第二个是:

countyGroup state   county  other_data
    1       IL      123     …
    1       IL      123     …
    2       MI      365     …
    1       IL      123     …
    3       AK      65      …
    4       IL      546     …
    5       MI      689     …
    6       AK      32      …

变量countyGroup唯一地标识statecounty.第二个数据集包含countyGroupstatecounty.第一个数据集仅包含countyGroup.我需要在第一个数据集中生成两个变量(statecounty).

Variable countyGroup uniquely identifies both state and county. The second data set contains countyGroup, state and county. The first data set contains only countyGroup. I need to generate two variables (state and county) in the first data set.

我尝试使用merge匹配值:

use dataset1
merge 1:m countyGroup using dataset2, keepusing(state state cntyfp) update replace

我得到的结果是重复的行...我尝试了1:1却不起作用...我总是可以drop这些重复的行,但是我想从一开始就正确地合并它们.

The result that I get is the duplicate rows...I tried 1:1 it did not work...I can always drop those duplicate rows, but I wanted to merge them correctly from the beginning.

推荐答案

我们需要了解重复的行(Stata的术语是观察").如果它们在所有变量上都是相同的,则没有额外的信息,并且使用duplicates drop使其最简单,最简单的方法是在merge之前使用它们.

We need to know about the duplicate rows (Stata's term is "observations"). If they are identical on all variables, there is no extra information, and it's cleanest and simplest to use duplicates drop to get them out of the way before the merge.

duplicates是用于管理重复项的通用工具.

duplicates is a general tool for managing duplicates.

如果其他变量上有不同的信息,请在此处告诉我们更多有关其的信息以及您的目标.

If there is different information on the other variables, tell us more about what that is and your goals here.

(LATER)您发布的数据集

(LATER) With your datasets you posted

   merge 1:m countyGroup using dataset2

似乎可以正常工作.

这篇关于Stata.如何匹配1:m关系中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆