stata 用户_384852955_1119h_40

cap:mkdir 0119h
cd "F:\BaiduNetdiskDownload\1973~2024 年降水量面板数据(含栅格数据)\区县"
fs *.xlsx
local ci=0
foreach file in `r(files)'{
    import excel "`file'", sheet("Sheet1") firstrow clear
    local ci=`ci'+1
    save e:\stata17\0119h\aa`ci',replace
}
cd e:\stata17
use 0119h\aa1,clear
forvalues ii=2/`ci'{
    append using 0119h\aa`ii'
}
save 0119h\shui,replace



cd "F:\BaiduNetdiskDownload\1973~2024 年气温面板数据\区县"
fs *.xlsx
local ci=0
foreach file in `r(files)'{
    import excel "`file'", sheet("Sheet1") firstrow clear
    local ci=`ci'+1
    save e:\stata17\0119h\bb`ci',replace
}
cd e:\stata17
use 0119h\bb1,clear
forvalues ii=2/`ci'{
    append using 0119h\bb`ii'
}
save 0119h\qiwen,replace


cd "F:\BaiduNetdiskDownload\1973~2024 年气温面板数据\城市"
fs *.xlsx
local ci=0
foreach file in `r(files)'{
    import excel "`file'", sheet("Sheet1") firstrow clear
    local ci=`ci'+1
    save e:\stata17\0119h\cc`ci',replace
}
cd e:\stata17
use 0119h\cc1,clear
forvalues ii=2/`ci'{
    append using 0119h\cc`ii'
}
save 0119h\qiwen1,replace


cd "F:\BaiduNetdiskDownload\1973~2024 年降水量面板数据(含栅格数据)\城市"
fs *.xlsx
local ci=0
foreach file in `r(files)'{
    import excel "`file'", sheet("Sheet1") firstrow clear
    local ci=`ci'+1
    save e:\stata17\0119h\dd`ci',replace
}
cd e:\stata17
use 0119h\dd1,clear
forvalues ii=2/`ci'{
    append using 0119h\dd`ii'
}
save 0119h\shui1,replace


use 0119h\shui,clear
merge 1:1 县代码 日期 using 0119h\qiwen
drop _merge
save 0119h\jieguo1,replace

use 0119h\jieguo1,clear
gen tt=0
local cc 降水量 最高气温 最低气温
foreach var of varlist `cc'{
    recode `var'(.=0)
}
replace tt=1 if 降水量>50 | 最高气温<=-10 | 最低气温>=35
bys 县代码 year:egen shu=count(日期) if tt==1
bys 县代码 year:egen shu1=max(shu)
replace shu1=shu1/360

duplicates drop 县代码 year,force
drop 降水量 平均气温 最高气温 最低气温 tt shu
recode shu1(.=0)
rename shu1 极端天气占比
sort 省 市 县 year
save 0119h\jieguo2,replace

python:
import pandas as pd
df = pd.read_stata(r"e:\stata17\0119h\jieguo2.dta")
df.to_excel(r"e:\stata17\0119h\jieguo2x.xlsx", float_format="%.6f",index=False)   
end

 

posted @ 2025-11-21 08:54  myrj  阅读(4)  评论(0)    收藏  举报