Stata |简单操作1(sort、gsort、order、list、rename、renvars、drop)

ln()

sort、gsort、order

  • sort、gsort对观测值排序
  • order对变量排序
  • sort升序排列
  • gsort可通过“+”、“-”指定升序降序
  • 多变量可以组合

list xxx in a/b

  • 显示第a到b个观测值

rename

  • 改变量名

renvars

  • 批量修改变量名
renvars price weight / p w
  • 添加前缀后缀
renvars price weight, postfix(_hhh)
renvars price weight, prefix(hhh_)

(*)

  • 表示任意多个字母或数字

(?)

  • 表示一个字母或数字
. gen lnwage = ln(wage)

. gen lnwage1 = ln(wage) if married
(206 missing values generated)

. gen sqrt_wage = sqrt(wage)

. list *wage in 1/5

     +---------------------------------------+
     | wage      lwage     lnwage   sqrt_w~e |
     |---------------------------------------|
  1. |  3.1   1.131402   1.131402   1.760682 |
  2. |  3.2   1.175573   1.175573        1.8 |
  3. |    3   1.098612   1.098612   1.732051 |
  4. |    6   1.791759   1.791759    2.44949 |
  5. |  5.3   1.667707   1.667707   2.302173 |
     +---------------------------------------+

. edit

. list wage* in 1/5

     +------+
     | wage |
     |------|
  1. |  3.1 |
  2. |  3.2 |
  3. |    3 |
  4. |    6 |
  5. |  5.3 |
     +------+

. list *wage in 1/10

     +---------------------------------------+
     | wage      lwage     lnwage   sqrt_w~e |
     |---------------------------------------|
  1. |  3.1   1.131402   1.131402   1.760682 |
  2. |  3.2   1.175573   1.175573        1.8 |
  3. |    3   1.098612   1.098612   1.732051 |
  4. |    6   1.791759   1.791759    2.44949 |
  5. |  5.3   1.667707   1.667707   2.302173 |
     |---------------------------------------|
  6. |  8.8   2.169054   2.169054    2.95804 |
  7. |   11   2.420368   2.420368   3.354102 |
  8. |    5   1.609438   1.609438   2.236068 |
  9. |  3.6   1.280934   1.280934   1.897367 |
 10. |   18   2.900322   2.900322   4.263801 |
     +---------------------------------------+

. rename educ education

. replace wage = 15 if wage > 15
(16 real changes made)

. list wage if wage >= 15

     +------+
     | wage |
     |------|
 10. |   15 |
 15. |   15 |
 16. |   15 |
 59. |   15 |
 66. |   15 |
     |------|
105. |   15 |
112. |   15 |
170. |   15 |
186. |   15 |
229. |   15 |
     |------|
245. |   15 |
260. |   15 |
278. |   15 |
326. |   15 |
343. |   15 |
     |------|
440. |   15 |
476. |   15 |
505. |   15 |
522. |   15 |
     +------+

. gen byte educ_d = 0

. edit

. rename education educ

. replace educ_d = 1 if educ > 12
(212 real changes made)


. drop west

. drop west south
variable west not found
r(111);

. edit

. edit

. drop 1/3
1 invalid name
r(198);

. drop in 1/3
(3 observations deleted)

. drop _ all
variable _ not found
r(111);

. drop _all

. use wage1.dta, clear

. order educ married wage

. edit

. //按指定顺序排列

. order _all, alpha

. //按字母序排列

. use wage1.dta, clear

. sort wage

. list wage in 1/5

     +------+
     | wage |
     |------|
  1. |  .53 |
  2. |  1.4 |
  3. |  1.5 |
  4. |  1.5 |
  5. |  1.6 |
     +------+

. gsort wage

. list wage in 1/5

     +------+
     | wage |
     |------|
  1. |  .53 |
  2. |  1.4 |
  3. |  1.5 |
  4. |  1.5 |
  5. |  1.6 |
     +------+

. gsort +wage

. list wage in 1/5

     +------+
     | wage |
     |------|
  1. |  .53 |
  2. |  1.4 |
  3. |  1.5 |
  4. |  1.5 |
  5. |  1.6 |
     +------+

. gsort -wage

. list wage in 1/5

     +------+
     | wage |
     |------|
  1. |   25 |
  2. |   23 |
  3. |   22 |
  4. |   22 |
  5. |   22 |
     +------+

. gsort wage, gen(numb)

. list wage in 1/5

     +------+
     | wage |
     |------|
  1. |  .53 |
  2. |  1.4 |
  3. |  1.5 |
  4. |  1.5 |
  5. |  1.6 |
     +------+

. list numb wage in 1/5

     +-------------+
     | numb   wage |
     |-------------|
  1. |    1    .53 |
  2. |    2    1.4 |
  3. |    3    1.5 |
  4. |    3    1.5 |
  5. |    4    1.6 |
     +-------------+

. //生成序号


  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值