1. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
S D NG STATA 10.0 PHN TCH TH NG K
TRONG NGHIN C U KHOA H C
GI I THI U PH N M M STATA 10.0
TS. BS T ng Kim H ng
A. CI T STATA V CH NG TRNH CHUY N I D LI U
1. Ci t STATA theo c叩c b c sau 但y:
1/ Ch y file autorun.exe
2/ Ch n Next r i next n u kh担ng mu n thay i t棚n, t ch c, v ng i s d ng.
3/ Ch n Stata /MP n u laptop thu c lo i DuoCore. Ch n Stata/SE n u laptop kh担ng
thu c lo i DuoCore.
4/ Ch n Next, r i Next, r i Next n u kh担ng thay i t棚n v v tr鱈 th m c ch a
Stata c ng nh Data c a Stata. Stata s b t u ci t.
5/ Ch n Finish khi Stata ci t xong.
6/ Vo Program t狸m v m Stata 10. Xu t hi n b n ng k箪.
7/ M file Code.doc d湛ng c叩c codes c坦 s n v i n vo b ng ng k箪. i n xong
b m OK. Ch ng tr狸nh Stata 10 t ng m ra.
8/ Ch n Yes tr l i Would you like to enable automatic update checking?
2. Ci t ch ng tr狸nh StatTransfer 9
- Tr棚n d!a CD, t狸m th m c StatTransfer9
- T狸m t"p tin StaTransfer9Setup.exe v nh p 炭p vo t"p tin ny, ch n Run b t u
ci t, ch n Next. Ch n I agree trong License agreement r i Next n u kh担ng thay
i t棚n v v tr鱈 th m c ch a StaTranfer9, vi c kh i ng ci t s b t u.
- Ch n Finish khi Stata ci t xong.
1
2. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
- L u 箪: N u Output File Type (Lo i File #c ch n chuy n i) kh担ng ph i l
Version 10 th狸 vo Options(4) ch$nh l i cho 炭ng
2
3. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
- B ng d i 但y m担 t c叩c lo i STATA. T湛y vo nhu c u v c u h狸nh m叩y t鱈nh m ta c坦
th ch n l a lo i STATA th鱈ch h#p nh t s d ng
B. M T S L C V STATA
Stata l m t ph n m m th ng k棚 d湛ng nh"p, x l箪, ph但n t鱈ch s li u. Theo m担 t t%
b ng tr棚n, Stata c坦 th ch y #c tr棚n nhi u h i u hnh, nh ng d湛 v i h i u hnh
no, Stata c ng c坦 th i u khi n #c b&ng d嘆ng l nh ( 叩nh l nh vo khung command)
ho c b&ng menu (ch n l nh tr棚n thanh menu).
Do b nh c a Stata b nh h ng b i k鱈ch th c c a file d' li u, n棚n khi lm vi c tr棚n
b d' li u c坦 k鱈ch th c l n ch炭ng ta c n t ng l #ng b nh dnh cho Stata b&ng c叩ch
d湛ng l nh set memory (vi t t t l set mem). V鱈 d ch炭ng ta c坦 th t ng b nh c a Stata
l棚n 800 megabyte b&ng l nh
set mem 800m
Ngoi ra n u ch炭ng ta mu n t ng s l #ng bi n s t i a c坦 th x l箪 th狸 s d湛ng l nh set
matsize. V鱈 d ch炭ng ta c坦 th t ng s l #ng bi n s t i a c n x l箪 l棚n 800 b&ng c叩ch
叩nh l nh nh sau
set matsize 800
1. Kh i ng Stata
Khi nh p 炭p vo bi u t #ng Stata tr棚n mn h狸nh Desktop th狸 ch ng tr狸nh Stata s hi n
ra nh sau:
3
4. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
- Thanh menu c坦 c叩c menu File ( 坦ng m t"p tin); Edit (hi u ch$nh); Prefs (t湛y ch n);
Data (c叩c x l箪 tr棚n s li u); Graphics (v th ); Statistics (th c hi n vi c ph但n t鱈ch s
li u) ; User (ng i s d ng); Window (m ra c叩c c a s ), Help (tr# gi炭p)
- Thanh c担ng c g m c叩c n炭t c担ng c sau:
+ Open (m file data)
+ Save (L u file data)
+ Print results (In k t qu )
+ Log begin/close log (B t u/ 坦ng.file log file l u k t qu ph但n t鱈ch)
+ New viewer (M c a s viewer ra s d ng ch c n ng help)
+ Bring graph window to front ( em c a s th ra tr c)
+ New do-file editor (Bi棚n t"p/t o m i file do file l u ch ng tr狸nh ph但n t鱈ch
t c l c叩c l nh ch y ch ng tr狸nh ph但n t鱈ch)
+ Data editor (Bi棚n t"p s li u s a ch'a, th棚m b t s li u)
+ Data browser (Duy t s li u - Xem s li u nh ng kh担ng s a ch'a)
+ Clear--morecondition (X坦a l nh more ti p t c ch y ch ng tr狸nh)
+ Break (Ng ng l nh ang ch y ho c ng ng ch ng tr狸nh ang ch y)
- B n c a s t% tr棚n xu ng d i bao g m
+ C a s Review (c叩c l nh v%a ch y xong s hi n l棚n tr棚n c a s ny, mu n ch y
l i l nh no, con tr( ngay t i l nh 坦 v nh p 1 c叩i, l nh 坦 s #c chuy n xu ng c a
s command chu)n b th c hi n, n u nh p 炭p, l nh 坦 s #c th c hi n)
+ C a s Results (mu en) th hi n k t qu ph但n t鱈ch
+ C a s Variables (c叩c bi n s c a file s li u ang s d ng, mu n ch n ph但n
t鱈ch bi n s no th狸 sau khi 叩nh l nh, con tr( ngay t i bi n s 坦, nh p chu t 1 l n,
bi n s 坦 s #c chuy n xu ng c a s l nh)
4
5. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
+ C a s Commands (c a s l nh l n i ta c坦 th 叩nh c叩c l nh vo)
2. L u l nh/ch ng tr狸nh ph但n t鱈ch
担i khi trong qu叩 tr狸nh ph但n t鱈ch s li u ta c n ph i th c hi n r t nhi u l nh m i t #c
n k t qu cu i c湛ng (v鱈 d c n ph i t o ra c叩c bi n m i, ph但n t鱈ch n bi n r i m i n
ph但n t鱈ch a bi n), kh担ng m t nhi u th i gian (v c坦 th qu棚n c叩c l nh 達 t o) ch炭ng
ta c n l u l i c叩c l nh ny.
Nh p chu t vo n炭t c担ng c New do-file editor, m t c a s m i s m ra, 坦 l c a s
Stata do-file editor.
ta
C坦 th vi t l nh ho c c t/d叩n c叩c l nh 達 ch y t% c a s commands vo 但y, b m n炭t
Save l u (khi l u xong trong m叩y t鱈nh s c坦 1 file .do 坦 ch鱈nh l file l nh ch y
ch ng tr狸nh). M*i l n m file d' li u ph但n t鱈ch, l i nh p chu t vo n炭t c担ng c New
do-file editor, ch n file .do 達 l u m . N u mu n ch y h t ton b c叩c l nh 達 vi t
trong ch ng tr狸nh th狸 con tr( ngay t% l nh u ti棚n sau 坦 th c hi n nh sau:
Tools -> Do to bottom
N u ch$ mu n ch y vi l nh trong ch ng tr狸nh th狸 叩nh d u kh i (c叩c) l nh c n ch y r i
th c hi n nh sau:
Tools -> Do selection
3. L u l i k t qu ph但n t鱈ch
K t qu ph但n t鱈ch #c th hi n tr棚n c a s Stata Results, nh ng c a s ny ch$ cho ph辿p
xem l i k t qu ph但n t鱈ch g n 但y. N u ch y m t ch ng tr狸nh ph但n t鱈ch di th狸 ton b
k t qu ph但n t鱈ch kh担ng th th y h t tr棚n c a s Results. V狸 v"y mu n l u tr' l i ton b
k t qu ch炭ng ta c n l u ch炭ng trong file log. Nh p chu t vo n炭t c担ng c Log
begin/close log th狸 ch炭ng ta th y hi n ra c a s
5
6. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
C坦 2 lo i file log ta c坦 th l u: file lo i formatted log (.smcl) l lo i file #c m c nh,
v file lo i log (.log). Mu n l u file d i d ng no th狸 ch n ng d+n, r i t t棚n file
l u
N棚n nh l c n ph i t o/m log file tr c khi ch y l nh k t qu m i #c l u trong file
log. N u kh担ng t o/m log file tr c th狸 Stata kh担ng t ng l u k t qu trong log file
Mu n xem l i k t qu 達 l u th狸 nh p chu t vo n炭t c担ng c Log begin/close log, ta s
th y hi n ra c a s Stata Log Options
Ch n View snapshot of log file r i b m OK xem. Khi mu n ch m d t vi c l u k t qu
trong log file th狸 ch n close log file r i OK. N u sau khi 達 坦ng log file r i ho c 達
ng ng s d ng Stata, nh ng sau 坦 ta l i mu n s d ng l i v mu n lm vi c tr棚n log fie
n'a th狸 l i nh p chu t vo n炭t c担ng c Log begin/close log, nh ng l n ny c a s Stata
6
7. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
Log Options c坦 h i kh叩c m t ch炭t. N u ta ch$ c坦 箪 nh xem k t qu th狸 ch n View
existing file (read-only), n u mu n ti p t c l u ti p k t qu ph但n t鱈ch (ti p n i ph n 達
l u) th狸 ch n Append to existing file, c嘆n n u quy t nh l u m i hon ton th狸 ch n
Overwrite existing file
7
8. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
BI T P S D NG STATA NH P S LI U
- H達y d湛ng Stata nh"p 15 records u ti棚n c a b d' li u sau
1. nh ngh a c叩c bi n s
- t t棚n bi n s
+ Nh"p gi叩 tr vo tr c-> con tr( t i bi n s c n t t棚n-> Nh p chu t (ta th y hi n
ra m t c a s 坦 l Variable Properties -> t t棚n
8
9. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
- nh ngh a t棚n bi n s
+ Data -> labels -> label variable -> ch n bi n s c n label t棚n trong 担 variable
+ t label trong 担 new variable label-> submit
+ Mu n label ny #c g n vo bi n s ta mu n nh ngh!a th狸 ch n Attach a label to a
variable
Ho c khi nh p chu t vo bi n s t t棚n, th y hi n ra c a s Variable Properties th狸
cho label lu担n
- nh ngh a c叩c gi叩 tr c a bi n s
Data -> labels -> label values -> Define or modify (value labels) -> Khi nh p chu t vo
但y s th y hi n ra m t c a s kh叩c 坦 l c a s label define -> Define ( ch n bi n s
c n nh ngh a gi叩 tr )
9
10. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
+ Khi ta nh p chu t vo define th狸 s th y hi n ra m t c a s m i 坦 l c a s Define
new label. H達y 叩nh nh ngh!a c a bi n s m ta mu n label -> Ok
+ Khi ta ch n Ok th狸 l i c坦 1 c a s kh叩c xu t hi n, 坦 l c a s Add value. Cho gi叩 tr v
ch* Value v qui c c a gi叩 tr 坦 vo ch* text (V鱈 d Value 1, Text Nam) r i b m OK.
Khi xong nh ngh!a c a 1 gi叩 tr r i th狸 c a s Add value v+n c xu t hi n, ta l i th棚m
vo gi叩 tr v nh ngh!a kh叩c (V鱈 d Value 2, Text Nu). C lm ti p t c nh v"y cho n
khi ta nh ngh!a xong t t c c叩c gi叩 tr -> 坦ng c a s ny l i -> Close
+ Sau khi 達 nh ngh!a c叩c gi叩 tr c a bi n s xong n u mu n g n c叩c nh ngh!a c a c叩c
gi叩 tr ny vo bi n s th狸 lm nh sau:
Data-> labels -> label values -> Assign value labels to variable -> Attach a value label
to a variable -> ch n variable-> ch n value label -> submit -> OK
+ Lm ti p t c cho n khi nh ngh!a xong c叩c bi n s
10
11. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
- Xem l i c叩c gi叩 tr c a bi n s
Data-> labels-> label values-> list value labels
2. L u l i file d li u v a bi棚n t p
Sau khi ch$nh s a s li u xong, 坦ng c a s data editor l i th狸 s th y hi n ra c a s sau:
Ch n accept changes l u l i nh'ng thay i tr棚n s li u m ta v%a lm.
3. Sort bi n s /Merge files/ t l i t棚n bi n s
- Sort c叩c bi n s (chu n b merge file)
Data -> Sort -> Ascending sort
- Merge files/merge c叩c cases
Data -> Combine datasets -> Merge two datasets
- t l i t棚n bi n s
Data -> Variable utilities -> Rename variable -> Rename a single variable -> Ch n bi n
s c n rename trong 担 existing variable name-> t t棚n bi n m i trong 担 new
variable name
4. T o bi n s m i/ i n!i dung bi n s hi n c坦/T o bi n s ph但n lo i t bi n s li棚n
t"c
- T o bi n s m i
Data -> Create or change variables -> Create a new variable -> t t棚n m i cho bi n s
trong 担 new variable name -> Thay i n i dung bi n s trong 担 contents of new
varble
- i n!i dung c#a bi n s hi n c坦
Data -> Create or change variables -> Change contents of variable-> Ch n bi n s
trong 担 variable-> New contents
VD: replace sex = 0 if sex==2
- T o bi n s ph但n lo i t bi n s li棚n t"c
Data -> Create or change variables -> Other variable transformation commands->
Recode categorical variable -> Ch n bi n s trong 担varibles-> Ra i u ki n
VD: recode age min/20=1 21/40=2 41/max=3
Bi t p: S d ng file framingham
+ T o bi n s m i th%a c但n & CHA v i c炭 ph叩p nh sau:
- gen TC = bmi
- recode TC min/24.999=0 25/max=1
- gen CHA = 1 if sbp>=140 & dbp>=100
11
12. L p Ph ng ph叩p NCKH Ch ng tr狸nh CUD UPNT03
- replace CHA = 0 if sbp<140 | dbp<100
5. Gi /b$ bi n s /s cases, thay % i th& t' c叩c bi n s trong b! s li u
- Gi' ho c b( bi n s
Data -> Variable utilities -> Keep or drop variables
- Gi' ho c b( s cases
Data -> Variable utilities -> Keep or drop observations
- Thay i th t c a bi n s trong b s li u
Data -> Variable utilities -> Change order of variables in dataset
Ho c
Data -> Variable utilities -> Relocate variable
12