全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
7238 10
2018-02-08
近期需要stata进行统计,特别是统计图,总结了做图命令如下,希望能够给战友帮助。

STATA GRAPHICS

Graphics Basics

sysuse auto, clear
graph bar (mean) mpg turn, by(foreign)
graph bar (mean) mpg turn, over(foreign)
graph hbar (mean) mpg turn, over(foreign)
graph hbar (mean) mpg, over(foreign) over(class)
graph hbar (mean) mpg, over(class) over(foreign)
graph hbar (mean) mpg, over(class) over(foreign, sort(1) descending)
graph hbar (sum) mpg turn, over(class) stack
graph hbar (sum) mpg turn, over(class) by(foreign)
graph hbar (sum) mpg turn, over(class) by(foreign) stack
graph dot (mean) mpg, over(class)
graph dot (mean) mpg, over(class) over(foreign)
graph matrix mpg price turn, half
graph pie, over(class)
graph pie mpg turn trunk, plabel(_all name)

Scatter and Two-way Plotting (Examples)

scatter mpg weight
scatter mpg weight, sort
scatter mpg weight, sort connect(1)
scatter mpg weight, sort title("MPG versus Weight") subtitle("Year 2006")
scatter mpg weight, title("MPG versus Weight") caption("Source: Stata Corp. 2006")
scatter mpg weight, title("MPG versus Weight") xsize(4) ysize(3)
scatter mpg weight, ytitle("MPG (Mileage)") xtitle("Car Weight")
scatter mpg weight, title("MPG versus Weight") ylabel(#8) xlabel(0(2000)6000)
scatter mpg weight, title("MPG versus Weight") ylabel(minmax) xlabel(minmax)
scatter mpg weight, title("MPG versus Weight") yscale(log) xlabel(#5) // log scales
scatter mpg weight, sort xline(4000) yline(25)
scatter mpg weight, title("MPG versus Weight") msymbol(triangle)
scatter mpg weight || fpfit mpg weight
twoway fpfitci mpg weight
twoway fpfitci mpg weight || scatter mpg weight, m(d)
scatter mpg weight, sort title("MPG versus Weight") m(diamond) by(foreign)
scatter mpg weight, sort m(t) by(foreign, total row(1))
twoway fpfitci mpg weight, sort m(t) by(foreign, total row(1))
twoway fpfitci mpg weight || scatter mpg weight, sort m(t) by(foreign, total row(1))
scatter mpg turn weight
scatter mpg turn weight , yline(30) xline(3500)
scatter mpg trunk turn weight
scatter mpg weight || scatter trunk weight || scatter turn weight
scatter mpg weight, sort c(1) || line trunk weight, sort || scatter turn weight
twoway (line mpg weight, sort c(1)) (dropline trunk weight, sort) (scatter turn weight)

Plotting by Functions

twoway function y=x^3, range(-5 5) xsize(4) ysize(3) xlabel(#10) xline(0)
twoway function y=normalden(x), range(-5 5) xsize(4) ysize(2) xlabel(#10) xline(0)
twoway function y=1/sqrt(2*_pi)*exp(-x^2/2), range(-5 5) xsize(4) ysize(2) xlabel(#10) xline(0)
twoway function y=normalden(x), range(-4 -1.96) xlabel(#10) xline(0) recast(area) || function y=normalden(x), range(1.96 4) recast(area) || function y=normalden(x), range(-1.96 1.96) lstyle(foreground)
twoway function t=tden(3, x), range(-5 5) xsize(4) ysize(2) xline(0)
twoway function t=tden(1, x), range(-5 5) xsize(4) ysize(2) color(blue) lstyle(p1solid) xlabel(-5(1)5) recast(area) || function z=normden(x), range(-5 5) color(maroon) lwidth(thick)
scatter gear_ratio headroom, xsize(4) || function y=x, range(0 5)
twoway function c=chi2(1,x), range(0 5) xsize(4) ysize(3) yline(.5)
twoway function c=Fden(5, 10, x), range(0 5) xsize(4) ysize(3) yline(.3)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2018-2-8 16:20:47
Probability Distribution相关的命令

binomal(h,k,p) // joint cumulative distribution of bivariate normal
chi2(df,x) // cumulative chi squared distribution
chi2tail(n,x) // reverse of chi2()
F(df1, df2, f) // cumulative F distribution
Ftail(df1, df2, f) // reverse cumulative (upper-tail) F
normal(z); normal(1.96) // returns .9750002
ttail(df, t) // reverse cumulative (upper-tail) T
uniform() // uniform distributionreverse cumulative (upper-tail) T
di chi2tail(10,18.31) // returns .04995417, p-value
di F(5, 10, 3.325) // returns .9499661
di Ftail(5, 10, 3.325) // returns .05000, the pa-value
di (1-normal(z))*2 // compute the p-value for the two-tailed test
di ttail(20, 2.086) // returns .02499818
di ttail(df, t)*2 // compute the p-value for the two-tailed test
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-2-8 16:21:38

Reshaping Data Sets相关命令


  • set obs 100 // to change the numnber of observations
  • sort male grade
  • gsort -grade name, gen(rank)
  • append using c:\data\class
  • app using c:\data\class, keep(id state q1-q10)
  • expand 5 in -10/-1 // duplicate observations n-1 times
  • merge using school // one-to-one merging
  • merge state using school // match merging
  • merge state using school university, update replace
  • joinby id using secondary, unmatched(master) // unm(both), unm(using)
  • move male grade
  • order grade male // order variables as listed
  • rename male gender; /* from male to gender */
  • expand 5 if state=="IN" // duplicate a subset of observations
  • collapse a b (sd) c (count) d (max)
  • collapse a b (sd) c (count) d (max), by state
  • contract gender degree area, freq(count) zero
  • reshape long choice, i(id) j(orders)
  • stack best1-best3, into(best) clear
  • pkshape id row col1-col3, order(abc cab bca) outcome(y) sequence(rows) treat(treat) period(columns)
  • compress // all variable
  • compress name grade
  • xpose, clear varname
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-2-8 16:23:21

Advanced Models

  • boxcox //Box-Cox regression model
  • eivreg // errors-in-variables regression
  • fracpoly // Fractional polynomial regression
  • frontier //Stochastic frontier models
  • glm // generalized linear model
  • intreg //interval regression
  • ivreg //instrumental variables (two-stage least squares) regression
  • ivreg dv iv1 iv2 (iv3= x1 x2 x3) iv4 iv5
  • mfp //multivariable fractional polynomial models
  • mvreg //multivariate regression
  • newey //Regression with Newey-West standard errors
  • nl //nonlinear least-squares estimation
  • orthog //Orthogonalize variables and compute orthogonal polynomials
  • prais dv1 rhs, rho(tscorr) twostep //Prais-Winsten two-step
  • prais dv1 rhs, rho(dw) // iterative two-step
  • prais dv1 rhs, rho(dw) corc // Cochrane-Orcutt
  • qreg //Quantile (including median) regression
  • reg3 //three-stage estimation for systems of simultaneous equations
  • reg3 (dv1 x1 x2) (dv2 x1 x3)
  • reg3 (dv1 dv2 = x1 x2 x3)
  • reg3 (dv1 dv2 = x1 x2 x3) (dv3 x1 x3)
  • rocfit //fit ORC model
  • rreg //robust regression
  • stcox //fit Cox proportional hazards model
  • streg //fit parametric survival model
  • sureg //Zellner's seemingly unrelated regression
  • stepwise //stepwise estimation
  • treatreg //treatment-effects model
  • treatreg y x1 x2 x3, treat(x4=z1 z2) twostep
  • vwls //variance-weighted least squares




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-2-8 16:24:12

PANEL DATA相关命令


  • tsset group year // set group and time
  • xtreg y x1 x2, re i(year) // random effect model
  • xtreg y x1 x2, fe i(group) // random effect model
  • xtreg y x1 x2, be i(group) // between effect model
  • areg // linear regression with a large dummy-variable set
  • xtabond // Arellano-Bond linear, dynamic panel-data estimator
  • xtcloglog // Random-effects, population-averaged cloglog models
  • xtgee // fit population-averaged panel-data models using GEE
  • xtfrontier // stochastic frontier models for panel data
  • xtgls // fit panel-data models using GLS
  • xthtaylor // Hausman-Taylor estimator for error components models
  • xtinreg // random-effects interval data regression models
  • xtivreg // Instrumental variables and two-stage least squares
  • xtlogit //fixed-effects, random-effects, population-averaged logit
  • xtmixed // multilevel mixed-effects linear regression
  • xtprobit // random-effects and population averaged probit models
  • xttobit // random-effects tobit models
  • xtnbreg //fixed-effects, random-effects, and population-averaged NB
  • xtpcse // Prais-Winsten models with panel-corrected standard errors
  • xtpoisson //fixed-effects, random-effects, population-averaged Poisson
  • xtrc // random-coefficients models
  • xtregar // fixed-and random-effects linear models with an AR(1)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-2-8 16:26:55
参数统计和非参统计的命令

T-Test

  • ttest grade==10
  • ttest grade, by(male)
  • ttest grade, by(male), unequal welch
  • ttest math=english; ttest math==english, unpaired
  • ttesti 100 88.1 5.2 90; /* N mean sd hypothesis */
  • ttesti 100 88.1 5.2 200 91 10.2; /* N1 mean1 sd1 N2 mean2 sd2 */
  • ttesti 100 88.1 5.2 200 91 10.2, unequal
  • mean // estimate means
  • total // estimate totals
  • ratio // estimate ratios
  • proportion // one- and two-sample tests of proportions
  • ci // confidence intervals for means, proportions, and counts


ANOVA
  • anova score gender
  • anova score gender year gender*year
  • oneway score gender, tabulate
  • loneway //large one-way ANOVA, random effect, and reliability
  • sdtest // Variance-comparison test
  • Related: .manova; .pkshape; .xtmixed

MULTIVARIATE ANALYSIS

Correlation Analysis

  • correlate gnp interest inflation
  • corr gnp interest inflation, covariance
  • pcorr x1-x10 // partial correlation coefficients
  • pwcorr gnp interest inflation, sig
  • pwcorr gnp interest inflation, print(5) // .05 significance level
  • pwcorr gnp interest inflation, sig star(.05) // .05 level

Factor Analysis

  • factor x1-x30 // by default pcf (principal component factor)
  • factor x1-x30, ml // maximum likelihood factor
  • factor x1-x30, factors(5)
  • rotate, varimax // orthogonal, oblique, quartimax, equamax, parsimax, promax
  • pca // principal component analysis

Other Analysis

  • alphar // Cronbach's alpha
  • ca // correspondence analysis
  • canon // Canonical correlation
  • cluster // cluster analysis
  • mvreg // multivariate regression
  • manova // multivariate MANOVA
  • mds // multidimensional scaling for two way data
  • mdslong
  • mdsmat
  • biplot

NONPARAMETRIC ANALYSIS

  • swilk math english
  • sfrancia x1-x10
  • ranksum //Equality tests on unmatched data
  • signrank math=english // Equality tests on matched data
  • runtest // test for random order
  • spearman x1-x10
  • kwallis score, by(gender)
  • ksmirnov math, by(area)
  • alpha x1-x10, item
  • kappa eval1 eval2
  • bitest //Binomial probability test
  • prtest // one- and two-sample tests of proportions

END
为了不增加网站负担,请根据需要下载附件。

祝各位战友学习顺利!!!

附件列表

stata常用命令汇总.docx

大小:31.7 KB

只需: 8 个论坛币  马上下载

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群