# 数据获取与处理工作日志 / Data Acquisition & Processing Log

**项目**: 资源重配置效率（RE）指数 / Resource Reallocation Efficiency Index  
**执行环境**: Linux sandbox, Python 3.13, R 4.x  
**执行日期 / Date**: 2026-05-22

---

## 一、数据源访问验证 / Data Source Access Verification

| 数据源 / Source | URL | HTTP状态 | 实际访问 | 备注 / Notes |
|---|---|---|---|---|
| World Bank API (WGI) | `https://api.worldbank.org/v2/country/{iso}/indicator/{code}?source=3` | 200 | ✓ | Source ID = 3 是关键，原代码（GE.EST）无效，正确为`GOV_WGI_GE.EST` |
| World Bank API (WDI) | `https://api.worldbank.org/v2/country/{iso}/indicator/{code}` | 200 | ✓ | 默认source=2 |
| QoG Standard Time-Series | `https://www.qogdata.pol.gu.se/data/qog_std_ts_jan25.csv` | 200 | ✓ | 59MB, 2009变量, 12392行 |
| V-Dem v15 直接下载 | `https://v-dem.net/media/datasets/Country_Year_V-Dem_Full+others_CSV_v15.zip` | 失败 (272B 占位符) | ✗ | 改用QoG嵌入版（QoG包含全部V-Dem主指标） |
| Fraser Institute Direct | `https://www.fraserinstitute.org/economic-freedom/dataset` | 403 | ✗ | 改用QoG嵌入版（`fi_*`变量） |
| IMF DataMapper API | `https://www.imf.org/external/datamapper/api/v1/...` | 200 但 0 bytes | ✗ | 部分指标空 |
| ICRG 完整数据 | `https://www.prsgroup.com/` | N/A (付费订阅) | ✗ | 用QoG中的`icrg_qog`复合指标替代 |
| data360 V-Dem CSV | `https://data360files.worldbank.org/...VDEM_CORE.csv` | 200 | ⚠ 752MB过大 | 备选未采用 |

**结论 / Conclusion**: 通过 **World Bank API + QoG Standard Dataset** 组合，可在不需要付费订阅的情况下覆盖所有RE指数所需的核心变量。

## 二、最终采用的数据组合 / Final Data Composition

### 19个G20主权成员（不含欧盟，因QoG无EUU聚合数据）
ARG, AUS, BRA, CAN, CHN, FRA, DEU, IND, IDN, ITA, JPN, KOR, MEX, RUS, SAU, ZAF, TUR, GBR, USA

### 时间跨度
2000–2023 (24年) × 19国 = 456 国-年观测

### 变量清单 / Variable Inventory (17 indicators)

**V 维度 (Velocity / Reaction Elasticity)**
| 变量 | 来源 | 描述 | 覆盖率 |
|---|---|---|---|
| `wbgi_rqe` | WGI | Regulatory Quality | 95.8% |
| `wbgi_pve` | WGI | Political Stability | 95.8% |
| `wbgi_vae` | WGI | Voice & Accountability | 95.8% |
| `wbgi_rle` | WGI | Rule of Law | 95.8% |
| `fi_reg` | Fraser | Regulatory Freedom | 95.8% |
| `fi_legprop` | Fraser | Legal System & Property | 95.8% |
| `wdi_taxrev` | WB WDI | Tax Revenue %GDP | 80.9% |
| `V_govexp` | WB WDI | Gov Expenditure %GDP | 78.9% |

**C 维度 (Conversion Rate)**
| 变量 | 来源 | 描述 | 覆盖率 |
|---|---|---|---|
| `wdi_internet` | WB WDI | Internet Users %pop | 97.4% |
| `C_rd` | WB WDI | R&D Expenditure %GDP | 90.8% |
| `C_hitech` | WB WDI | High-Tech Exports %mfg | 69.1% |
| `vdem_academ` | V-Dem | Academic Freedom | 100% |

**F 维度 (Institutional Friction)**
| 变量 | 来源 | 描述 | 覆盖率 |
|---|---|---|---|
| `vdem_corr` | V-Dem | Political Corruption Index | 100% |
| `wbgi_cce` | WGI | Control of Corruption | 95.8% |
| `wbgi_gee` | WGI | Government Effectiveness | 95.8% |
| `icrg_qog` | ICRG (via QoG) | Quality of Government | 100% |
| `fi_sog` | Fraser | Size of Government | 95.8% |

## 三、数据处理流程 / Processing Pipeline

```
Step 1 (script 01-03): Raw data acquisition
   ├── World Bank API: 6 WGI + 6 WDI indicators
   ├── QoG download: 16 selected variables
   └── Merge → 456 rows × 17 vars, 7.08% missing

Step 2 (script 04): Iterative MICE imputation
   └── 549 missing cells → 0 missing (sklearn IterativeImputer, 20 iter)

Step 3 (script 04): Min-Max normalization → [0,1]
   └── F-direction reversal for "reverse-coded" variables

Step 4 (script 04): PCA-based weighting
   ├── V dimension: PC1 explains 66.7% variance
   ├── C dimension: PC1 explains 56.4% variance
   └── F dimension: PC1 explains 76.0% variance

Step 5 (script 04): RE = V·C/(1+F) aggregation
   └── 5 versions: RE, RE_eq, lnRE, RE_timevar, RE_domain×3

Step 6 (script 04): Bootstrap uncertainty (B=500)
   └── Dirichlet weight perturbation → 90% CI

Step 7 (script 05): Reliability & validity testing
   ├── Cronbach's α: V=0.914, C=0.660, F=0.878
   ├── CR/AVE all dimensions ≥ 0.5/0.7 thresholds
   ├── Convergent validity: r > 0.9 with WGI/ICRG
   ├── Temporal stability: ρ = 0.980
   └── Predictive validity: tested with COVID-19 GDP impact

Step 8 (script 06): Visualization (10 figures)

Step 9 (script 07): Excel multi-sheet export (15 sheets)
```

## 四、关键决策记录 / Key Decision Log

1. **使用QoG替代直接V-Dem下载**: V-Dem官网需要表单提交，直接URL返回272字节占位文件。QoG标准时序数据集（Jan 2025版本）完整嵌入了V-Dem v14的所有主要指标，可作为完美替代。

2. **WGI正确变量代码**: World Bank API中WGI变量需使用 `GOV_WGI_*` 前缀+`source=3` 参数，原始`GE.EST`格式（无前缀）返回空数据。该问题在原研究计划文档中未提及。

3. **F维度方向处理**: WGI/ICRG的"高分=好治理"，需取反作为F；V-Dem `vdem_corr`本身就是"高=腐败严重"=高F，方向已正确。统一处理后所有F变量"高=高摩擦"。

4. **C维度Cronbach α=0.66**: 略低于0.7阈值，因C包含异质指标（互联网普及、R&D、高科技出口、学术自由）。但CR=0.83、AVE=0.57均达标，整体收敛效度可接受。

5. **样本数限制**: 19个G20国家+24年=456观测。若需扩大可纳入OECD全部38国（约912观测），但本研究聚焦G20以保持政策可比性。

## 五、可复现性 / Reproducibility

所有代码已模块化保存：
- `01_wb_data_acquisition.py` - WB WDI数据获取
- `01b_wgi_acquisition.py` - WGI专项获取  
- `02_extract_qog_vars.py` - QoG变量提取（探索）
- `03_full_data_extraction.py` - 完整变量整合
- `04_re_index_construction.py` - **核心RE指数构建（5项创新）**
- `05_reliability_validity.py` - 信度效度检验
- `06_visualizations.py` - 10个图表生成
- `07_export_excel.py` - Excel多工作表导出
- `RE_Index_Analysis.R` - R语言稳健性补充分析

依赖：`pandas, numpy, scipy, scikit-learn, matplotlib, seaborn, openpyxl, requests`

环境复现命令：
```bash
pip install pandas numpy scipy scikit-learn matplotlib seaborn openpyxl requests
python3 01_wb_data_acquisition.py && python3 01b_wgi_acquisition.py && \
python3 03_full_data_extraction.py && python3 04_re_index_construction.py && \
python3 05_reliability_validity.py && python3 06_visualizations.py && \
python3 07_export_excel.py
```

总运行时间: 约 30 秒（已实测）。
