Stata Common Commands Summary (34, including use examples) _stata

Source: Internet
Author: User
Tags natural logarithm square root first row truncated

1. Input: Enter data

Example: Inpurt x y

1 4

2 3.5

3 7

End


2, by: According to the value of a variable to analyze

For example: by group,sort:regress y x1 x2//According to different groups, Y do regression analysis


3, Weight: weighted or frequency number

Example: fw= frequency variable///More used in the four-cell table data or the original data did not give all the values, only give the value and corresponding frequency number


4. If: Specify condition with conditional statement

Example: Drop if group==1|group==2//delete records with a group variable value of 1 or 2


5. In: Specify the range of observations and analyze the observed values in the range

Example: Replace x1= "123" in 100/200//change X1 variable value in 第100-200条 record to 123


6, for: To specify the variable

Example: For Y1-y10 z1-z5:regress @x1-x22

The y1-y10,z1-z5 respectively in x1-x22 to do regression, one-time representative 15 times regression, which is a substitution, representing Y1-y10, z1-z5


7, Function:

ABS (x) absolute value

EXP (x) exponential function

Log (x) natural logarithm

LOG10 (x) Common logarithms

sqrt (x) square root

Pseudo-random numbers in uniform distribution in uniform (x) generation (0,1)

Length (x) calculation lengths

SUBSTR (S,N1,N2) obtains a string of N2 characters starting from the N1 character of S

Real (x) converts a string s to a numeric function

Trim (x) remove the space before and after the string

int (x) removes the decimal part of the X and gets the whole number

SUM (X) sum

Max (x) min (x) Maximum minimum value

_n the current observed value position

Total number of _n observations


8. ren: renaming

Example: ren var1 var123//renaming var1 to Var123


9, des: Describe the basic situation of the database


10, Label: Add some instructions for the variable to show


11, sort: According to a variable from small to large sort

Gsort + +-: Sort by a variable from big to small or to large

Sort var1 var2: sorted by var1 size, same var1 sorted by var2 size


12. Drop: Delete variable or record

Drop X1 x2

Drop x1-x5

Drop if x<0\

Drop in 1/100

Drop if x==.| y==.

Drop _all//Empty database


13, Keep: With the drop corresponding to save the variable


14. Append: Vertical Connection Database


15, Merge: Horizontal connection Database


16. Gen: Generating New variables

Gen Bh=_n//Assign the internal number of the database to the variable BH


17, replace: Change the value of the variable

Replace Z=. If z=9//Replace all z=9 values with missing values

Renvars: Batch Modify variable name

Renvars x1-x5, prefix (mono_)//prefix x1-x5 with variable names of variable mono_; the suffix is postfix.


18. Set Obs: Increase blank record

Set OBS 20//Add 20 blank Records


19. Format: Change data format

Format TJRQ%TD//change TJRQ to date form


20, l:list the results listed


21, Su: The analysis of data description, the average standard is poor, and des different, des is to describe the number of database variables, format, etc.

Su x, D//X is a statistical description, if you add D, then it will be more detail


22, Centile: Percentile number calculation

Centile x, Centile (2.5,50,97.5)//Calculate the 2.5,50.97.5 percentile of the variable x


23, Tab: The frequency of the expression

tab sex//To calculate the frequency of each of the two genders

tab Sex Group//See gender distribution in each group

TAB group, SUM (x1)//X1 Statistical analysis in each group


24. CI: Calculating confidence interval


25. Straight Square Chart: Gra x, Bin (9) Xlab (10,20,30,40) Ylab (0,1,2,3) Norm Gap (4) B2 ("Height (cm)")

The X-ray histogram is divided into 9 groups, the x axis is the 10,20,30,40,y axis is 0,1,2,3, plus the normal distribution curve, the distance between the title and the axis (1-8), the lower axis plus the title is height (cm)

B1/T1/L1/R1 ("") add title to each axis

B2/T2/L2/R2 ("") add subheadings to each axis

Title to the picture plus the headline

Article: Gra x1 x2, Bar by (group) SH L1 ("Rate of Die") B1 ("Comparison of rate of die")

For x1,x2, the grouping variable is group, and the contrast between the two groups is 3:1, the left title rate of die, the next heading comparison of rate of die

Pie chart: GRA x1 x2 x3 x4 x5, Pie by (group) SH Total

Scatter plot and line graph: Connect (abbreviated c)--How to connect the scatter point:

. Not connected

L Straight Line Connection

s smooth curve connection

|| Two points connected to the same vertical line

J-Step Line connection

Symbol (abbreviated s)--graphics for individual scatter points:

O Big Circle

S generous block

T Big triangle Type

O Small Circle

D Small Diamond

P Small Plus

. Little Bit

Gra y x, Xlab Ylab C (L) s (d)

Box diagram: Gra y x, oneway/twoway box


26, single sample mean T test: ttest x=14.02 (total mean number μ)

Ttesti n Mean sdμ

Paired T-Test: TTest x1==x2

T-test of two-sample mean number: TTest x1==x2,unpaired

TTest x, by (group)


27, Variance Analysis:

Fanchazzi Test: Sdtest x1=x2

Sdtest x, by (group)

Test of normality: Sktest x

Single Factor Variance analysis: oneway corresponding variable grouping variables

Two-Factor variance analysis: ANOVA corresponding variable group variable 1 group variable 2

Multivariate analysis of variance: Anova x a b c ... a*b b*c a*b*c ...//product items represent interactions


28. Comparison of ratio and composition ratio: Tab var1 VAR2 [fw= frequency variable]

CHI2 Pearson Card Square inspection

Exact Fisher exact probability method

If the original Data rxc table: Tabi The first row of numbers from left to right \ second row from left to right ... \ Last row from left to right, row chi2 exact


29. Cohort study (exposure, no exposure):

IR case variable exposure variable time variable./IRS a B n1 n2

CS case Variable exposure variable/CSI a B C D

Case-control study (onset, no morbidity): CCI a B c D


30, Grade information:

Genrank Series Genrank Rankx=x

Signtest sign test similar to T-Test, Signtest x= constant, Signtest x1=x2, Signrank x1=x2

Signrank symbol rank and test

Ranksum/wilcoxon two sample rank and test Wilcoxon var, by (Group_var)

Kwallis multi-sample rank and test (Kruskal-wallis) Kwallis Var,by (Group_var)

Spearman level related Spearman x y

Ktau grade Correlation (Kendall) Ktau x y


31. Linear correlation and regression: related Corr y x

return reg y X

Estimation and prediction Pre Yhat

Paint gra y yhat L1 L2 L3 L4 X, C (. lssss) s (OIIII) Xlab () Ylab ()

32. Multivariate linear regression and stepwise regression:

Scatter chart matrix: Gra y x1 x2, Matrix

Correlation coefficient matrix: Corr

Multivariate regression equation: reg y x1 x2//normalized partial regression coefficients, reg y x1 x2, Beta

Stepwise regression: stepwise y x1-x4, forward Fe (2.73)//α equals 0.05 when F boundary value is 2.73,FE representative fenter Opt-in Standard, FS representative Fstay Elimination standard

Stepwise regression method: Forward,backward,stepwise,stepwise forward For example: Step y x1-x4, steps Fe (2.5) FS (2.6) Back


33. Logistic regression:

Logit y x [fw=f]

Blogit y x1 x2 x3/glogit y x1 x2 X3

can also do the stepwise logistic regression


34, Survival curve:

Median lifetime: survsum time variable truncated variable by (group variable)

Survival curve: Kapmeier time variable truncated variable by (group variable)//Kaplan-meier survival curve

Survival comparison: Two groups: Wilcoxon time variable truncated variable by (group variable)

Multiple groups: Logrank time variable truncated variable by (group variable)

Cox analysis: Cox time variable independent variable, dead (truncated variable)


                                                                              

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.