我有看起来像这样的面板数据:
ID year dummy
1234 2007 0
1234 2008 0
1234 2009 0
1234 2010 1
1234 2011 1
2345 2008 0
2345 2009 1
2345 2010 1
2345 2011 1
3456 2008 0
3456 2009 0
3456 2010 1
3456 2011 1
随着更多的观察遵循相同的模式和更多与这个问题无关的变量。
我想建立一个 ID 处理样本,其中虚拟变量在 2010 年“切换”(当 year<2010 时为 0,当 year>=2010 时为 1)。在上面的示例数据中,1234 和 3456 将在样本中,而 2345 则不在。
我对 SAS 相当陌生,我想我对 CLASS 和 BY 语句还不够熟悉,无法弄清楚如何做到这一点。
到目前为止,我已经这样做了:
data c_temp;
set c_data_full;
if year < 2010 and dummy=0
then trtmt_grp=1;
else pre_grp=0;
if year >=2010 and dummy=1
then trtmt_grp=1;
run;
但这对数据的面板方面没有任何作用。我不知道如何做最后一步,只选择每年 trtmt_grp 为 1 的 ID。
感谢所有帮助!谢谢!