Title: Session I How to use STATA
1Session IHow to use STATA Basic Data
Management Commands
2What will be covered?
- Introduction to STATA Software
- General Guidelines in Data entry
- Data Management in STATA
3Introduction to STATA
4(No Transcript)
5(No Transcript)
6Open Close the Output File
- To open the log file
- log using directory\path\filename.log
- log using d\trials\zinc.log
- To close
- log close
zinc.dta
7To Open Log (Output) File
8To Close the Log File
9Append Replace the Existing Log File
To append the existing log file log using
d\trials\zinc.log, append To replace the
existing log file log using d\trials\zinc.log,
replace
10Open the Data File
To open the data file use directory\path\filename
.dta use d\trials\zinc.dta To save save
zinc.dta
zinc.dta
11 To Make A New Directory
12To Change the Directory
13General Guidelines in Data Entry
- Rows in the datasheet should contain individual
information - Record. - Each column should contain values of a single
entity of all the individuals Variable. - Variable name should not exceed more than eight
characters. - Variables can be either numeric or string or
alphanumeric. - A numeric variable must posses only numbers.
- In any datasheet, identification number is must.
14DATA DESCRIPTION
15Data Management using STATA
16Data Management using STATA
- Inputting Data
- Editing Data
- Creating and Changing Variables
- Saving and Reusing Data
- Data Reorganization
- Merging and Appending datasets
17Inputting Data
- Enter data from keyboard
- input varlist
- input str25 name age str1 sex
- Best way is copy from excel and directly paste
the data to STATA editor - Transfer from other programs
18Arithmetic Operators
(Addition) - (Subtraction)
(Multiplication) / (Division) (Raise to
power)
19Relational Operators
gt (greater than) lt (less than) gt
(greater than or equal) lt (less than or
equal) (equal) ! (not equal)
20Logical Operators
(and) (or) ! (not equal)
21Expressions
If used when expression is to be specified with
the condition In used when range is to be
specified in the condition
22Editing Data
- Edit using Data Editor
- edit varlist if in
- edit treatment centre age
- edit treatment age if centre3agegt25
23Browsing Data
- List using Data Editor
- browse varlist if in
- browse treatment centre age
- browse treatment age if centre3agegt25
24Do this Exercise
- Edit the following
- pcode, treatment and cough only for centre 4
- browse for the same and feel the difference
zinc.dta
25 Creating Changing Variables
- Create new variable
- generate newvar exp if in
- gen totstl24 s1_tstool_wt s2_tstool_wt
s3_tstool_wt
26Do this Exercise
- Generate total stool output from 0-48 hours
zinc.dta
27Creating Changing Variables
contd
- Change contents of existing variable
- To replace
- replace oldvar exp if in
- replace sodium1 . if sodium10
- To recode
- recode varlist (erule) (erule) ... if in
- recode age min/61 7/112 12/max3 , gen(agecat)
Rule Example Meaning
/ nonmissing missing 3 1 2 4 5 4/8 3 nonmissing 2 missing 9 3 recoded to 1 2 and 4 recoded to 5 4 through 8 recoded to 3 all other nonmissing to 2 all other missing to 9
28Do this Exercise
Ex 1 Replace all zeros in serum Potassium as
missing. Ex 2 Recode pre admission diarrhea
duration into 0-24h, 25-72h and gt 72h
zinc.dta
29Creating Changing Variables
contd
- Rename the existing variable
- rename oldvarname newvarname
- ren tlc_t2 tlc2
- ren tlc_t3 tlc3
- Eliminate the existing variable
- To drop
- drop varlist
- drop name address
- To keep
- keep varlist
- keep idno age sodium albumin-tlc
zinc.dta
30Saving Reusing Data in Stata Format
- To Save data
- save filename.dta
- save zinc, replace
- clear
- To reuse data
- use filename
- use zinc
zinc.dta
31Data Reorganization
- Sorting observations and changing variable order
- To sort
- sort varlist in
ascending - sort pcode
- Move specified variables to front of dataset
- order varlist
- Move one variable to specified position
- move varname1 varname2
- Alphabetize specified variables and move to
front of dataset - aorder varlist
zinc.dta
32Data Reorganization contd
- Convert data from wide to long
- reshape long stubnames, i(varlist) j(varname)
- reshape long albumin, i(pcode) j(time)
Wide Shape Data
Long Shape Data
33Data Reorganization contd
- Convert data from long to wide
- reshape wide stubnames, i(varlist) j(varname)
- reshape wide albumin, i(pcode) j(time)
Long Shape Data
Wide Shape Data
34Do this Exercise
Convert serum zinc from wide to long shape data
using zinclab.dta
zinclab.dta
35Answer!!!
zinclab.dta
36Merging Appending Datasets
- To append datasets
- append using filename
- use zinc1.dta
- append using zinc2.dta
- To merge datasets
- merge varlist using filename
- use zinclab
- sort pcode
- save zinclab, replace
- use zincprognostic
- sort pcode
- merge pcode using zinclab
zinclab.dta
37Do this Exercise
Merge file 1 (zinclab.dta) with file 2
(zincprognosis.dta)
zinclab.dta
38Session IIData Cleaning Preparing Data for
Analysis
39Preparing Data for Analysis
- Inclusion criteria 35 months old children
40Preparing Data for Analysis contd
41Do this Exercise
Inclusion criteria for the study was pre
admission diarrhea duration lt 7 days Ex 1
Convert pre admission diarrhea duration from
hours to days using zincclean.dta Ex 2 Find
values beyond expected range
zinc.dta
42Answer!!!
43Preparing Data for Analysis contd
44Preparing Data for Analysis contd
45Preparing Data for Analysis contd
?
46Do this Exercise
Do similar exercise for hemoglobin using zinc.dta
zinc.dta
47Answer!!!
48Preparing Data for Analysis contd
What do you mean by 1 2???
zinc.dta
49Preparing Data for Analysis contd
Label name
50Preparing Data for Analysis contd
zinc.dta
What is wrong and how to correct it???
51Preparing Data for Analysis contd
52Preparing Data for Analysis contd
53Do this Exercise
Generate total stool output for first 48 hrs
zinclean.dta
54Preparing Data for Analysis contd
55Do this Exercise
Draw a boxplot and identify extreme value, if
any, for s2_tstool_wt using zincclean.dta
zincclean.dta
56 Session III Introduction to Basic Data
Analysis
57What will be Covered?
- Descriptive Statistics
- Parametric tests
- Non-parametric tests
58Analyses
- Univariate (one variable at a time)
- Bivariate (two variables at a time)
- Multivariate (more than two variables at a time)
59Descriptive Statistics
60Univariate Analysis
Quantitative Mean Median Range/IQ Range SD
Categorical Frequency percentage
61Descriptive Statistics-Categorical Variable
Can we label the variables???
62Contingency Table
63Contingency Table contd
64Contingency Table contd
65Contingency Table contd
66Contingency Table contd
Immediate commands
67Do this Exercise
Ex 1 Draw a crosstab between treatment and
withdrawn using zinc.dta Ex 2 Draw a crosstab
between treatment and diarr24, diarr48
zinc.dta
68Descriptive Statistics-Quantitative Variable
69Summary in Detail
70Do this Exercise
- Calculate summary statistics for the following
variables - Total stool output 0-48h
- Total ORS intake 0-24h
- Total stool frequency in 24h before admission
- Serum zinc at admission
zinc.dta
71Summary Statistics by Group
72Do this Exercise
- Calculate summary statistics by treament for
the following variables - Total stool output 0-48h
- Total ORS intake 0-24h
- Total stool frequency in 24h before admission
- Serum zinc at admission
zinc.dta
73Percentile Values
74Do this Exercise
- Calculate 3rd and 97th percentile value by
treatment for the following variables - Total stool output 0-48h
- Total ORS intake 0-24h
zinc.dta
75Session IV (A)Bi-variate Analyses
76Analysis of Clinical Trial Data
77Analysis of Clinical Trial Data
- Compare patient characteristics at the time of
randomization and baseline measurements between
the groups - Assess the difference in outcome variable(s)
between the groups (adjusting for any imbalance
in patient characteristics or baseline outcome
variables)
78 Bi-variate Analyses
- Categorical vs Categorical
- Categorical vs Quantitative
791. Categorical Vs Categorical
-
- Unrelated Related
- Chi square test McNemar test
- Fishers Exact test
-
X2, Y2
Xgt2, Ygt2
- Unrelated
- - Chi square test
- Fishers Exact test
X Group variable Y Outcome variable
80Chi-square test
81Do this Exercise
Is there a difference between the proportion of
patients requiring IV fluids in the two treatment
groups?
zinc.dta
82Chi-square Test/Fishers exact Test by Group
83Comparison of two proportions
84Do this Exercise
- Is there a difference in the proportion of
patients recovered in rota virus negativity
between the two treatment groups? - 91 of patients recovered in treatment A (n248)
and 95 of patients recovered in treatment B
(n252). Test these proportions and find out the
p-value
zinc.dta
85McNemars Chi-square Test
86McNemars Chi-square Test contd
87Do this Exercise
Is there a shift in zinc deficiency from baseline
after giving treatment B?
zinc.dta
882. Categorical vs Quantitative
Parametric
Non-Parametric
X2 Y Normal
X2 Y Non Normal
Unrelated Related Students t test Paired t test
Unrelated Related Wilcoxon ranksum Wilcoxon
signrank
Xgt2 Y Non-Normal
Xgt 2 Y Normal
Unrelated Related Kruskal Wallis
Freidmans test
Unrelated Related One way Repeated
ANOVA measures ANOVA
89Students t Test for Independent Groups
90Students t Test for Independent
Groups contd
91What is the Difference in the Total ORS Intake in
the First 24h between the Two Groups?
92Transformations
93Transformations contd
94Do this Exercise
Ex 1 What is the difference in total stool
output 0-48hours between the two groups? Ex 2
Is there a difference between total duration of
diarrhea (in hours) (varname tot_du_dia_h)
between the two treatment groups?
zinc.dta
95Geometric Mean if Log Transformation is Used
96Do this Exercise Ex Calculate the geometric
mean for stool output 0-48 hours
zinc.dta
97Paired t-Test
98Do this Exercise
Is there a change in zinc value from baseline
after giving treatment B?
zinc.dta
99Is there a Change in the Serum Zinc from Baseline
to Recovery between Two Treatment Groups?
Discuss..
100One-way ANOVA
Analysis of Variance
101Multiple Comparisons
Difference in means of zinc values between age
group of 6 gt 12
P-value
102Non-Parametric Methods
103Is there a difference in total stool output in
the first 24h between the two treatment groups?
Answer Wilcoxon Ranksum test
104Is there a difference in total stool output in
the first 24h between the two treatment groups?
contd
Answer Wilcoxon Ranksum test
105Do this Exercise
Is there a difference in total diarrhea duration
between the two groups?
zinc.dta
106Is there a Change in zinc from baseline after
giving treatment A?
Answer Wilcoxon signed-rank test
107Is There a Change in zinc from baseline after
giving treatment A?
Answer Wilcoxon signed-rank test
108Do this Exercise
- Is there any difference in zinc from baseline
after giving treatment B?
zinc.dta
109Is there a difference in total stool output
across age groups?
Answer Kruskal-Wallis Test
Contd
110Is there a difference in total stool output
across age groups?
Answer Kruskal-Wallis Test
Contd
111Is there a difference in total stool output
across age groups?
Answer Kruskal-Wallis Test
Contd
112Is there a difference in total stool output
across age groups?
Answer Kruskal-Wallis Test
Contd
113Do this Exercise
- Is there any difference in serum zinc (at
admission) across the age groups ?
zinc.dta