基于几个条件的新变量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