** set working folder
cd " C:\...\EDYI_slab3 "

** start log file
log using lab3.log, replace



******************************
*
*   merge/append datasets
*
******************************

* add observations
use data1, clear
count
describe
list

append using data2
count
describe
list

* add variables (to data1 + data2)
merge 1:1 id using data3

count
describe
list

tab _merge

save fin_data, replace


******************************
*
*    HYPOTHESIS TESTING
*
******************************
use data_all, clear
sum
encode gender, gen(sex)
replace height=. if height==999
mvdecode weight, mv(-1)


******************************
*  Normality Test
******************************

** Kolmogorov - Smirnov
************************
summarize pressure
ksmirnov pressure = normal((pressure-94.21569)/10.50583)

quietly summarize pressure
return list

ksmirnov pressure = normal((pressure-r(mean))/r(sd))
ksmirnov pressure = normal((pressure-r(mean))/sqrt(r(Var)))

** Shapiro - Wilk
************************
swilk pressure

bysort sex: swilk pressure


******************************
*    compare means
******************************

** parametric
*****************

sum pressure

hist  pressure
hist  pressure, bin(5) normal

*one sample t-test
ttest pressure=90

** two samples t-test
sort sex
by sex: summarize pressure

hist  pressure, bin(5) normal by(sex)
hist  pressure if sex==1, bin(5) normal
hist  pressure if sex==2, bin(5) normal

ttest pressure, by(sex)

** paired t-test
ttest pbef=paft


** non-parametric
****************************

** one sample test
signtest pressure=50

** two samples test
ranksum pressure, by(sex)

** paired test
signrank pbef=paft


*********************************
*   compare standard deviations
*********************************
sum pressure

* Levene's test ( W0 )
robvar pressure, by(sex)


* alternative test
sdtest pressure, by(sex)


******************************
*    ANOVA
******************************

** parametric
**************

tab alcohol
replace alcohol=. if alcohol==9

oneway height alcohol

oneway height alcohol, tabulate bonferroni


** non-parametric
*********************

kwallis height, by(alcohol)


******************************
*  compare proportions, chi2
******************************

tab cigaret
replace cigaret=. if cigaret==99

gen smoke=0 if cigaret==0
replace smoke=1 if cigaret>0 & cigaret!=.

tab smoke sex, chi2 row col exp exact


******************************
*    correlation
******************************

** parametric
**************

hist height, bin(5) normal
hist weight, bin(5) normal

scatter weight height

pwcorr weight height
pwcorr weight height, sig obs


** non-parametric
*****************

spearman weight height












