微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

基于几个条件的新变量Stata

如何解决基于几个条件的新变量Stata

我有如下结构的三个变量:

pre_covid   change  post_covid
employed    Same         .
Housewif    Same         .
Business    diff      out of LF
employed    diff      unemployed
employed    Same         .
Housewif    Same         .

然而,对于那些自经济衰退开始以来状态没有改变的人,我想创建一个变量,如下所示:post-recession_status

pre_covid   change  post_covid   post_recession_status
employed    Same         .             employed 
Housewif    Same         .             Housewif 
Business    diff      out of LF        out of LF
employed    diff      unemployed       unemployed
employed    Same         .             employed    
Housewif    Same         .             Housewif 

covid 前后类别的 dataex 如下:

 1 "employed",modify
 2 "Unemployed",modify
 3 "out of LF",modify
 4 "Housewife",modify
 5 "student",modify

change 变量的 dataex 是:

Example generated by -dataex-. To install: ssc install dataex
clear
input float change 
2
2
1
1
end
label values change change 
label def change 1 "Different",modify
label def change 2 "Same",modify

解决方法

尽管进行了编辑,您的数据示例仍不完整且在几个次要细节中不一致:diffdifferentHousewifHousewifeUnemployed 或 {{ 1}},unemployed 不是定义的值标签。

仍然以类似的数据集为例(经过编辑,一些额外的代码,然后是 Business),然后是一些令牌代码。

dataex

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。