zoukankan      html  css  js  c++  java
  • stata数据分组

    1. 五分位(中位数)

    by year,sort:egen distance_ew_median=median(Ln_geodistance_ew)
    gen distance_ew_high=(Ln_geodistance_ew>distance_ew) if Ln_geodistance_ew!=.      //是否加median

    2. 分组的方法,分成三组,四组

    ssc install astile
    astile newvar=exp [if] [in] [, nquantils(#) qc(string) by(varlist)]

    其中,nquantils(#)表示将变量取值由小到大分为#个组,如nq(2)表示按中位数进行二等分。

    例如:

    bysort year: astile quart_SA = SAindex, nq(3)    //xtile quart_SA = SAindex, nq(3)
    replace quart_SA=0 if quart_SA==3|quart_SA==2 

    3. 按照百分位

    pctile 表示从小到大排列

    bysort year: egen DACC50=pctile(DACC), p(50)    
    gen DACC_group=1 if DACC>=DACC50      //0是下五分位,1是上五分位
    replace DACC_group=0 if DACC<DACC50 

     4. 分组计算均值中位数

    by year,sort:egen distance_ew_median=median(Ln_geodistance_ew)
    gen distance_ew_high=(Ln_geodistance_ew>distance_ew) if Ln_geodistance_ew!=.      //是否加median

    组内除该变量之外的变量均值

    bys industry2: egen total=total(q)
    bys industry2: gen N=_N
    gen average=(total-q)/(N-1)
  • 相关阅读:
    random(1)
    django(1)
    python复习
    bootstrap(1)
    jquery(2)
    Jquery(3)
    day17 正则表达式 re模块
    文字笔记
    MATLAB之数学建模:深圳市生活垃圾处理社会总成本分析
    MATLAB之折线图、柱状图、饼图以及常用绘图技巧
  • 原文地址:https://www.cnblogs.com/celine227/p/15005938.html
Copyright © 2011-2022 走看看