是r语言好用还是 stata好用

wangeunice 2021-09-18 16:33 423 次浏览 赞 63

最新问答

  • 车厘子妈妈

    常用的 Excel、SPSS、SAS、 R语言、stata、MATLAB等 Excel SPSS 作相对容易一些 sc-cpda 分析公众交流平台 详细【我】

    浏览 225赞 108时间 2023-10-15
  • 芳芳Flora

    sysuse auto, clear
    summarize mpg weight
    //summarize 后面可以接一个或多个变量,个数 均值 最小最大值
    summarize mpg, detail
    //会有关于其他的统计指标
    help summarize
    tabulate mpg, sort
    tabulate foreign
    //最好是分类变量去tabulate,展示各个种类有多少个,占多大比例(离散的)
    help tabulate
    sysuse nlsw88, clear
    tab occ
    //不同职业的样本在我的库里面分别有多少个,比例大小,总的样本数量是多少
    tab industry
    sysuse auto, clear
    tabstat mpg price weight rep78 , stat(n mean sd min median max) c(s)
    //c(s)是转置过来这个矩阵,默认阅读方式是:列是统计指标,行是变量名称
    help tabstat
    //下划线是代表可以简写,只写c(s)
    //可以规定format 总长度多少个单位,小数点前面,后面有多少个单位,统一成一个格式
    tabstat mpg price weight rep78 , by(foreign) stat(n mean sd min median max) c(s)
    //by是以什么分类展示

    //输出表格(不要复制):
    ssc install logout
    logout, save(summarize) tex word excel dec(3) replace: tabstat mpg price weight rep78 , stat(n mean sd min median max) column(s) long format
    //不建议导出成tex word 因为在Excel还要进一步编辑,xml格式的可以在excel打开 rtf是可以从word打开 就可以应用在论文里面了。replace替换原来的 dec(3)代表小数点后统一保留三位数,replace后面与之前一模一样 ,column是列
    logout, save(summarize) tex word excel dec(3) replace: tabstat mpg price weight rep78 , by(foreign) stat(n mean sd min median max) c(s)

    use nei_sample.dta, clear
    describe
    duplicates tag newid year, gen(dup)
    edit newid year if dup >= 195
    duplicates drop newid year, force
    help merge
    duplicates drop newid year, force
    //一个地方会有n个企业
    merge m:1 fips year using "county_na.dta"
    //根据county的代和时间调用
    //有三部分的merge,merge=1和2是不需要的地方 只保留3(matched) 因为没有企业的观测值(0),而mrege=1则是有企业的观测值(1),而merge=2没有政策的观测值(0)(观测到了企业污染,却没有观察到关于政策的变量)
    //我们关心企业所在的地区是否有环境政策

    //做一个最简单的回归,政策对污染的影响:(regress)
    foreach v of varlist reg_* {
    replace `v'= 0 if `v' == .
    }
    reg co reg_co
    gen lco = ln(co)
    reg lco reg_co
    //有0的问题
    //add a set of dummies(虚拟变量), tear , industry, county
    gen fips_st = substr(fips,1,2)
    //state(取fips编号的前两位)
    gen sic2 = substr(sic,1,2)
    //industry
    gen sic1 = substr(sic2,1,1)
    keep if sic1 == "2" | sic == "3"
    //manufacturing only
    gen lco = log(co)
    //generate log
    reg lco reg_co
    //reg_co代表有无监管,有就是1(非常不准)表中的_cons代表截距
    xi: reg lco reg_co i.year
    //按照年份,每年加一个虚拟变量,是这一年就是一
    //with year FE (根据每一年不一样回归 )
    bys year: egen id_sum = count(newid)
    //?
    xi : reg lco reg_co id_sum i.year
    //with year FE, multicolinearity
    //如果观测值是1996年的,那么iyear1996=1,这个统一的因素会影响所有的企业(宏观经济因素,所有企业都受影响),今年的这个企业和明年的这个企业外部环境是不一样的,是什么不重要,要capture这个东西
    xi : reg lco reg_co i.year i.sic2
    //with industry FE(不同产业的影响)
    xi : reg lco reg_co i.year i.sic2 i.fips_st
    //with state FE(省对环境保护的压力的影响)
    xi : reg lco reg_co i.year i.sic2 i.fips
    //with county FE
    xtset newid year
    //set panelex
    xi: reg lco reg_co i.newid
    //通过dummy
    xi: xtreg lco reg_co, fe
    //先进行差分 (常用)
    //这两行的结果相同

    xi: xtreg lco reg_co i.year , fe
    //year
    xi: xtreg lco reg_co i.year i.fips_st, fe
    //state fe
    xi: xtreg lco reg_co i.year i.sic2, fe
    //industry fe
    //下标都是固定效益 用希腊字母带下标 c是位置 j是行业 t为第t年的宏观经济形势/技术进步(系统性) i表示企业自身的固定效益,是观察不到的个体特征因素(有些企业管理水平天生高,低)
    sort newid sic2
    by newid: gen newsic2 = sic2[_N]
    xi: xtreg lco reg_co i.newsic2, fe
    //企业不更改行业属性

    //two-way fised effects with firm fixed effects

    xi:xtreg lco reg_co i.teay*i.newsic2, fe
    //industry-year FE

    xi:xtreg lco reg_co i.teay*i.fips_st, fe

    findit outreg2

    qui xi: xtreg lco reg_co i.year , fe
    outreg2 using result.xls, excel keep(reg_co) dec(3) addtext(Firm FE, Y,Year FE,Y,State-Year FE,n,Industry-Year FE,n)
    //dec(3)代表小数点后3位数 导出成excel格式

    qui xi: xtreg lco reg_co i.year*i.sic2 , fe
    outreg2 using result.xls, excel keep(reg_co) dec(3) addtext(Firm FE, Y,Year FE,Y,State-Year FE,n,Industry-Year FE,n)

    qui xi: xtreg lco reg_co i.year*i.sic2 i.year*i.fips_st , fe
    outreg2 using result.xls, excel keep(reg_co) dec(3) addtext(Firm FE, Y,Year FE,Y,State-Year FE,n,Industry-Year FE,n)

    17 本溪沈阳 任延昊 2019/5/6 20:14:42
    cd /Victor/stata
    //地图:
    findit spmap
    help spmap
    unicode encoding set gb18030
    unicode translate "china_label.dta"
    //必须先清零,然后运行一遍路径名 才能运行这两行命令
    use "china_label.dta", clear
    //example 1
    use china_label, clear
    gen xx = uniform()
    spmap xx using "china_map.dta", id(id) title("中国地图",size(*0.8)) label(label(ename) xcoord(x_coord) ycoord(y_coord) size(*.8)) plotregion(icolor(stone)) graphregion(icolor(stone)) fc(Greens) clnumber(8) oc(white ..) osize(medthin ..)
    //clnumbers 代表8种不同的绿色
    //example 2
    tab name
    replace name = subinstr(name, "省", "", .)
    replace name = subinstr(name, "市", "", .)
    replace name = subinstr(name, "回族自治区", "", .)
    replace name = subinstr(name, "壮族自治区", "", .)
    replace name = subinstr(name, "特别行政区", "", .)
    replace name = subinstr(name, "自治区", "", .)
    replace name = subinstr(name, "维吾尔", "", .)
    tab name
    //改名字
    foreach x of numlist 1/5{
    gen num `x'=uniform()
    }
    format x %9.3g
    foreach x of numlist 1/5{
    spmap `x' using "china_map.dta",id(id) title("中国地图", size(*0.8)) label(label(ename) xcoord(x_coord) ycoord(y_coord) size(*.8)) plotregion(icolor(stone)) graphregion(icolor(stone)) fc(Greens) clnumber(8) oc(white ..) osize(medthin ..) graph export "china0`x'.png", replace
    }
    cd /Victor/stata
    //地图:
    findit spmap
    help spmap
    unicode encoding set gb18030
    unicode translate "china_label.dta"
    //必须先清零,然后运行一遍路径名 才能运行这两行命令
    use "china_label.dta", clear
    //example 1
    use china_label, clear
    gen xx = uniform()
    spmap xx using "china_map.dta", id(id) title("中国地图",size(*0.8)) label(label(ename) xcoord(x_coord) ycoord(y_coord) size(*.8)) plotregion(icolor(stone)) graphregion(icolor(stone)) fc(Greens) clnumber(8) oc(white ..) osize(medthin ..)
    //clnumbers 代表8种不同的绿色
    //example 2
    tab name
    replace name = subinstr(name, "省", "", .)
    replace name = subinstr(name, "市", "", .)
    replace name = subinstr(name, "回族自治区", "", .)
    replace name = subinstr(name, "壮族自治区", "", .)
    replace name = subinstr(name, "特别行政区", "", .)
    replace name = subinstr(name, "自治区", "", .)
    replace name = subinstr(name, "维吾尔", "", .)
    tab name
    //改名字
    foreach x of numlist 1/5{
    gen num `x'=uniform()
    }
    format x %9.3g
    foreach x of numlist 1/5{
    spmap `x' using "china_map.dta",id(id) title("中国地图", size(*0.8)) label(label(ename) xcoord(x_coord) ycoord(y_coord) size(*.8)) plotregion(icolor(stone)) graphregion(icolor(stone)) fc(Greens) clnumber(8) oc(white ..) osize(medthin ..) graph export "china0`x'.png", replace
    }

    浏览 156赞 106时间 2022-11-05

是r语言好用还是 stata好用