0% found this document useful (0 votes)
22 views

Command For Stata

Howell are you How are you how are gou

Uploaded by

Emshaw Wendwesen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Command For Stata

Howell are you How are you how are gou

Uploaded by

Emshaw Wendwesen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Commands for t-test

Independent T-test ttest Milkyield (Response), by ( ration)/grouping


variable
Paired t-test ttest hf == lf (based on H0 we can change the
position of the variable)
ttest lf == hf
Single t-test ttest dailyweightgain (response) == 607
(hypothesized mean)

Commands for ANOVA

One way anova oneway pcv (response) treatments


(factor)

hist pcv,bin(5) normal


Two way anova anova pcv (response) drug (var
1)##feed (var 2)- 2 way full factional

Gen pcv_n = real(pcv) or


destring, replace----- Converting string
variables with numeric values into
numeric values

encode treatments, gen(drug)

encode feedingmanagement,
gen(feed)--- Converting string
variables with non-numeric values into
numeric values

anova pcv drug#feed- interaction


(2way)

by treatments, sort : summarize pcv ( to


analyze for each treatment)

mean pcv, over( drug)


hist pcv (response), normal (To draw
histogram)

histogram pcv

graph box pcv, over(treatments)

xi:anova pcv i.drug*i.feed

To import Data

By Command insheet using "C:\Users\Haile\Desktop\one way.csv"


insheet using "D:\Post Graduate\ADVANCED
BIOSTATISTICS\data\pigs_data.csv"

Command for regression

Simple linear reg priceperpig (response) numberofpigssoldmillions (factor)

twoway (scatter priceperpig numberofpigssoldmillions)- to


draw scatter plot

sc pig(predicted value) priceperpig


numberofpigssoldmillions, c(1)- ((to draw Scatterplot: price per
pig (both observed and predicted) in function of sales volume scatter
plot with linear (Y hat) line

sc-scatter plots are generated

predict pred(file name)- to calculate the expected value

predict hail (file name), stdp- to calculate standard error

gen lower=pred(predicted value file name)-1.96* hail (stdp


file name)
gen upper=pred+1.96* hail—this two used to calculate lower
and upper standard deviation
Multiple linear des- used to observe detail info of data

reg calvcon(response) age (factor)

reg calvcon age endomet mastitis metritis milkfev ovar


(response)

sc pred low up age

sc calvcon (response) pred(file name of predicted value) low


up age(continuous factor), c(i L L L) m(o i i i )----- the above
to use to draw scatter graph for lower and upper confidence
interval with predicted value and continuous factor variable
and response variable

testing interaction
The predicted values can be calculated (pred = coef(_cons) +
coef(age)*age + coef(metritis)*metritis + coef(ovarian)*ovarian)

*------ used to test interaction between discrete explanatory variable


xi:reg calvcon age i.metritis*i.ovar

predict pred(file name)

order calvcon pred age endomet mastitis metritis milkfev


ovar- to order the different factors as we want

est store a(file name)—used to save file while lrtest (model


simplification test

lrtest a(file name)—liklihood ratio test

stepwise,pr(0.05):reg calvcon age endomet mastitis metritis


milkfev ovar—to calculate stepwise function

predict res(file name), residual—used to calculate residual

hist res(residual file name), normal—used to check normal


distribution of residuals

qnorm res—similar to the above

swilk res—similar to the above/ Shapiro-Wilk W test for


normal data

predict stres, (the red one is predicted residual file


name)rstandard—used to check for Homoscedasticity

predict pred1(file name)--- expected value of


Homoscedasticity

sc stres(residual file name) pred1(file name of predicted


value)— scatter graph used to check for Homoscedasticity

hettest—official test for Homoscedasticity

lpoly res(residual file name) age(continuous factor)—used to


check for linearity (local polynomial smooth graph)

predict lev(file name), leverage--- used to estimate leverage


value (>2*(k+1)/n). To check whether there is outlier or not

gen lnage(file name)= ln(age)--- used to change continuous


explanatory var to mathematical(natural logarithm) value and
used to check linearity

predict rstand, rstandard

lpoly lnage rstand

list lev if lev >=0.83(leverage Value)

estat vif----- used to check collinearity

xi:reg weight i.var1i.var2----- use to code variable (use to


declare discrete variable )
corr age (y var) size (x var)---- command for linear correlation

Command used for chi square and logistic regression

Chi square Tab var1 var2, chi2


Tab var1 var2, exact--- for fisher exact test
Tab district (var1) trypsspp(var2), chi2 exact
Logistic Gen logit= logit (var1)---- logistic transformation
regression
Logit response explanatory, or------ use or

Logit response explanatory------- coefficient

Di exp (regression coefficient value)------ used to calculate OR


in stata

predict p

Predict xb(file name), xb (command for lineralized estimate

Gen p2=exp(xb)/(1+exp(xb))---- used to generate lineralized


estimate (predicted value). Exp (exponential), p2(file name),
xb(predicted file name)

gen pred=exp(xb)/(1+exp(xb))

predict stdp, stdp

gen lower=exp(xb-1.96*stdp)/(1+exp(xb-1.96*stdp))

gen upper=exp(xb+1.96*stdp)/(1+exp(xb+1.96*stdp))

list

Estat class ---used to test the overall usefulness of the model

Estat gof---- use to assess goodness-of-fit test


Gen pp(file name)=pred(predicted value)>=0.5------- used to
check the goodness of the fit

Lroc---- to draw roc curve used to test the overall usefulness of


the model

Multiple Glm response explanatory, family name link


logistic
regression glm microplus tmax tmin, family(binomial 1) link(logit) eform
(eform indicates exponential)

glm microplus tmax tmin, family(gaussian) link(identity) eform


(in such case it become linear regression)

Char define sex (omit)M--- used to omit the M from the


variable sex

Command for count data

Poisson regression Poisson reactor(response) type sex age (explanatory),


exposure (par/File name)—command to calculate poisson

xi: poisson reactors i.type i.sex i.age, exposure ( par)----


used to separate the different variable(e.g sex M&F)

estat gof—used to estimate the goodness of the fit of data


with the model

predict irr--- used to predict incidence rate ratio(irr)

xi: poisson reactors i.type i.sex i.age, exposure ( par) irr---


to report data in irr

hist reactor
xi: nbreg reactors i.type i.sex i.age, exposure ( par) irr---
used to calculate negative binomial regression

xi: glm reactors i.type i.sex i.age, family(poisson) link(log)


exposure ( par) eform--- glm function for poisson

xi: glm reactors i.type i.sex i.age, family(nbinomial)


link(log) exposure ( par) eform----- glm function for
negative binomial regression

Command for nonparametric tests


syntax for signtest/Non signtest dailyweightgain = 607
parametric
list dailyweightgain if dailyweightgain>607

list dailyweightgain if dailyweightgain==607

list dailyweightgain if dailyweightgain<607

signtest lf = hf

hist diff, normal


list diff if diff>0

list diff if diff<0

list diff if diff==0

hist diff, normal bin(5)


Wilcoxon signed-rank signrank lf = hf
test
sort diff
Two-sample Wilcoxon ranksum milkyield, by(ration) porder
rank-sum (Mann-
Whitney) test

Kruskal-Wallis kwallis air, by( benzaldehyde)


equality-of-
populations rank test/
one way anova/
Spearman syntax spearman age size
sc age size

Command for longitudinal data analysis


syntax for longitudinal data xtset Dogid--- used to declare panel variable
analysis
xi: xtreg bloodglucose i.diet, re

reshape---- to change wide data form to long form

add xt before any normal regression


syntax for mixed data analysis xi: reg t_lnscc h_size i.c_heifer i.t_season t_dim

xi: xtreg t_lnscc h_size i.c_heifer i.t_season t_dim, i(herdid)

robust models syntax svyset herd

xi: svy: reg t_lnscc h_size i.c_heifer i.t_season t_dim

estat eff-----is post estimation statistics for survey data

analysis of complex survey logistic tbb age


data syntax
svyset owner_name [pweight=tbweight]

svy: logistic tbb age


svyset owner_name [pweight=tbweight], strata(town)

svy: logistic tbb age


survival data analysis ci milkproductionkg

You might also like