match - 数据集中两个变量的模糊匹配
问题描述
如何在 Stata 数据集中的两个变量之间进行模糊匹配(大约 75% 的匹配)?
在我的示例中,Match_yes = 1
如果 in 的值Brand_1
存在于Brand_2
:
**Brand_1 Brand_2 Match_yes**
Samsung Samsung 1
Microsoft Apple 0
Apple Sony 1
Panasonic Motorola 0
Miumiu 0
Mottorrola 1
LG 0
如何获得Mottorrola
variable 下的值Brand_1
以产生 a ,因为它与variableMatch_yes = 1
中的值有 80% 相似?Motorola
Brand_2
解决方案
使用您的玩具示例:
clear
input strL(Brand_1 Brand_2)
Samsung Samsung
Microsoft Apple
Apple Sony
Panasonic Motorola
Miumiu
Mottorrola
LG
end
这是使用社区贡献的命令matchit
生成所需输出的“hack”:
local obs = _N
generate Cont = 0
forvalues i = 1 / `obs' {
forvalues j = 1 / `obs' {
replace Cont = 1 if Brand_1[`i'] == Brand_2[`j'] in `i'
generate b1 = Brand_1[`i'] in 1
generate b2 = Brand_2[`j'] in 1
matchit b1 b2, generate(simscore)
generate score`i'`j' = simscore
replace Cont = 1 if score`i'`j'[1] > 0.80 in `i'
drop b1 b2 simscore
}
}
drop score*
list
+------------------------------+
| Brand_1 Brand_2 Cont |
|------------------------------|
1. | Samsung Samsung 1 |
2. | Microsoft Apple 0 |
3. | Apple Sony 1 |
4. | Panasonic Motorola 0 |
5. | Miumiu 0 |
|------------------------------|
6. | Mottorrola 1 |
7. | LG 0 |
+------------------------------+
推荐阅读
- ios - UIView animateKeyFrames 未按预期工作
- java - Java中的这种代码结构是什么?
- tfs - 如何获得在 TFS 中运行的实时管道状态?
- python - for循环没有从列表中删除所有项目,解决方案是什么?
- android - WorkManager 的工作分组/链接,类似于 android-priority-jobqueue
- c# - 无法让 MultiBinding 工作
- apache-kafka - 如何运行 Kafka 休息的两个实例
- javascript - JQuery onclick 函数显示所有锚标记的相同 id
- filter - 如何在 ASP.NET 的 Kendo Grid 上设置初始过滤器
- google-aiy - AIY Vision Kit - CameraInference 是否总是抓取最新/当前帧?