现在有变量avg_wage,industry,想用住宿业和餐饮业人员的平均工资代替计算中等技能劳动力的平均工资,怎么写stata代码
时间: 2024-09-30 19:05:16 浏览: 36
wage-management.rar_工资
在Stata中,如果你想根据`industry`变量分别计算住宿业和餐饮业的平均工资,并将这两个行业的平均值作为`avg_wage`的新估计值,你可以使用`egen`命令结合`ifelse`语句。假设`industry`是一个包含行业名称的字符串变量,值可以是"住宿业"或"餐饮业",以下是一个示例代码:
```stata
* 如果 industry 是住宿业,则替换 avg_wage 为住宿业的平均工资
gen avg_wage_new = if industry == "住宿业" then avg_wage_by_industry1 else .
* 同样地,如果 industry 是餐饮业,则替换 avg_wage 新值为餐饮业的平均工资
gen avg_wage_new = if industry == "餐饮业" then avg_wage_by_industry2 else avg_wage_new
* 先假设你已经有了名为 avg_wage_by_industry1 和 avg_wage_by_industry2 的新变量,它们存储了对应行业的平均工资
replace avg_wage_new = avg_wage_by_industry1 if industry == "住宿业"
replace avg_wage_new = avg_wage_by_industry2 if industry == "餐饮业"
* 检查是否有缺失值,如果需要,可以用 mean replace 或 drop 来处理
list avg_wage_new if missing(avg_wage_new)
* 可能需要的数据清理步骤:
* gen avg_wage_by_industry1 = egen(平均工资, mean, wage_if_industry1) // 生成住宿业平均工资
* gen avg_wage_by_industry2 = egen(平均工资, mean, wage_if_industry2) // 生成餐饮业平均工资
```
在这个例子中,你需要先计算出住宿业(`avg_wage_by_industry1`)和餐饮业(`avg_wage_by_industry2`)的实际平均工资,然后再用`replace`命令更新`avg_wage_new`。
阅读全文