123456789101112131415161718192021222324 |
- import pandas as pd
- import pyreadstat
- if __name__ == "__main__":
- #读取CHARLS数据
- CHARLS_data = pd.read_csv("CHARLS_data_pollutants_mete.csv")
- CHARLS_data.to_csv("CHARLS_data_pollutants_exit.csv",index=False)
- CHARLS_data = pd.read_csv("CHARLS_data_pollutants_exit.csv")
-
- #增加一列死亡状态
- #0:未死亡
- #1:死亡
- #读取2013年的死亡数据
- exit, meta = pyreadstat.read_dta("/root/r_base/CHARLS/CHARLS2013/Exit_Interview.dta")
- exit['ID'] = pd.to_numeric(exit['ID'], errors='coerce').astype('Int64')
- exit["exit_year"] = exit["exb001_1"]
- CHARLS_data = pd.merge(CHARLS_data, exit[['ID', "exit_year"]], on = "ID", how="left")
- #读取2020年的死亡数据
- exit, meta = pyreadstat.read_dta("/root/r_base/CHARLS/CHARLS2020/Exit_Module.dta")
- exit['ID'] = pd.to_numeric(exit['ID'], errors='coerce').astype('Int64')
- exit["exit_year"] = exit["exb001_1"]
- CHARLS_data = pd.merge(CHARLS_data, exit[['ID', "exit_year"]], on = "ID", how="left")
- CHARLS_data.to_csv("CHARLS_data_pollutants_exit.csv",index=False)
|