本文介绍了识别类别变量的唯一级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个身份证号码清单,以及他们在特定日期获得的药品类型。

I have a list of person ids, and the types of medicines they got on specific dates.

我想创建一个变量 c的信息,以便显示可以直接复制和粘贴的数据示例。您需要一些工程使其易于使用。

Please find out about dataex from SSC to be able to show data examples that can be copied and pasted directly. Yours required some engineering to be made easy to use.

您的问题已经是Stata常见问题解答。在发布前仔细阅读常见问题是一个好主意。

Your problem is already a Stata FAQ found here. It is a good idea to look through the FAQs before posting.

* Example generated by -dataex-. To install: ssc install dataex
clear
input float p_id str8 agent_type float(wanted date)
1001 "thiazide" 1 15322
1001 "thiazide" 1 15442
1001 "thiazide" 1 15536
1001 "arb"      2 15580
1001 "CCB"      3 15609
1001 "arb"      2 15609
1001 "CCB"      3 15623
1001 "thiazide" 1 15623
1001 "arb"      2 15623
1001 "CCB"      3 15684
1001 "arb"      2 15684
2001 "ace_inhi" 1 14433
2001 "ace_inhi" 1 14458
2001 "ace_inhi" 1 14481
2001 "ace_inhi" 1 14539
2001 "CCB"      2 14566
2001 "ace_inhi" 1 14566
2001 "CCB"      2 14592
2001 "CCB"      2 14621
2001 "CCB"      2 14643
2001 "arb"      3 14643
2001 "CCB"      2 14671
end
format date %td

bysort p_id agent_type (date) : gen firstdate = date[1]
egen group = group(p_id firstdate agent_type)
bysort p_id (group date agent_type): gen count = sum(group != group[_n-1])
assert count == wanted

请注意,该代码考虑了在同一天首次使用两种或多种药物的可能性,同一个人。

Note that the code takes care of the possibility that two or more drugs are first used on the same day by the same person.

这篇关于识别类别变量的唯一级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:02