如何执行此移动性计算?

发布于 2025-01-30 14:08:19 字数 396 浏览 3 评论 0原文

我有关于公司之间发明家的流动性的数据。对于每个发明家,旧公司和新公司都有多行,每行都呈现她/他在各自公司中获得的专利(请参阅屏幕截图)。我只对此数据集中的两行感兴趣 - 该行包含了旧公司中发明家生产的最后一项专利,而该行包含新公司中的第一份专利。我如何仅保留每个发明家的这两行并删除其余的?该示例中的发明家是38592732,他从科学联盟搬到了阿迪尔。我只想保留62和63行并删除其余的。 - 在Stata或Excel方面的任何帮助将有所帮助。多谢。

I have the data on the mobility of inventors between firms. For each inventor, there are multiple rows in the old firm and the new firm, with each row presenting the patent she/he produced in a given year in the respective firm (please see the screenshot). I am only interested in two rows in this dataset - the row containing the last patent the inventor produced in the old firm and the row containing the first patent in the new firm. How do I keep only these two rows for each inventor and delete the rest? The inventor in the example is 38592732 who moved from Science Union to Adir. I only want to keep rows 62 and 63 and delete the rest. –
Any help in Stata or Excel will be helpful. Thanks a lot.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半岛未凉 2025-02-06 14:08:19

可重现的数据集(例如dataEx)将为您提供一个需要较少适应的解决方案,但是下面的示例应显示如何完成。

* Example generated by -dataex-. For more info, type help dataex
clear
input byte inventorID str1 patentID str9 firm int year
1 "A" "old_firm"  2000
1 "B" "old_firm"  2001
1 "C" "new_firm"  2002
1 "D" "new_firm"  2003
1 "E" "new_firm"  2004
1 "F" "new_firm"  2005
2 "G" "old_firm2" 2000
2 "H" "old_firm2" 2001
2 "I" "new_firm2" 2004
2 "J" "new_firm2" 2005
end

* Sort data on inventor and year
sort inventorID year

* Identify last patent as row where inventor is the same on the next row but firm is not
gen lastPatent  = (inventorID == inventorID[_n+1] & firm != firm[_n+1])
* Identify last patent as row where inventor is the same on the previous row but firm is not
gen firstPatent = (inventorID == inventorID[_n-1] & firm != firm[_n-1])

* Keep only rows categorized as first or last patent
keep if lastPatent == 1 | firstPatent == 1

A reproducible data set (using for example dataex) would have given you a solution that would have required less adaptation, but the example below should show you how it can be done.

* Example generated by -dataex-. For more info, type help dataex
clear
input byte inventorID str1 patentID str9 firm int year
1 "A" "old_firm"  2000
1 "B" "old_firm"  2001
1 "C" "new_firm"  2002
1 "D" "new_firm"  2003
1 "E" "new_firm"  2004
1 "F" "new_firm"  2005
2 "G" "old_firm2" 2000
2 "H" "old_firm2" 2001
2 "I" "new_firm2" 2004
2 "J" "new_firm2" 2005
end

* Sort data on inventor and year
sort inventorID year

* Identify last patent as row where inventor is the same on the next row but firm is not
gen lastPatent  = (inventorID == inventorID[_n+1] & firm != firm[_n+1])
* Identify last patent as row where inventor is the same on the previous row but firm is not
gen firstPatent = (inventorID == inventorID[_n-1] & firm != firm[_n-1])

* Keep only rows categorized as first or last patent
keep if lastPatent == 1 | firstPatent == 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文