UNIVERSIT DU QUBEC MONTRAL - Laboratoire d'études de la ...
UNIVERSIT DU QUBEC MONTRAL - Laboratoire d'études de la ...
UNIVERSIT DU QUBEC MONTRAL - Laboratoire d'études de la ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
generate sqrtx3 = sqrt(x3) if<br />
x3>=0<br />
generate abs_x4= abs(x4) Valeur absolue <strong>de</strong> x4<br />
generate trunc_x5 = int(5) Nombre entier obtenu en tronquant x5<br />
generate rnd_x6 = round(x6,.01) Valeur <strong>de</strong> x6 à <strong>de</strong>ux décimales<br />
generate str1 gen<strong>de</strong>r =<br />
string(sex)<br />
generate byte ngen<strong>de</strong>r =<br />
real(gen<strong>de</strong>r)<br />
generate startdate =<br />
mdy(mthvar,dayvar,yearvar)<br />
17<br />
Création d’une variable alphanumérique<br />
d’un caractère à partir <strong>de</strong> <strong>la</strong> variable<br />
numérique sex<br />
Création d’une variable numérique à partir<br />
<strong>de</strong> <strong>la</strong> variable alphanumérique gen<strong>de</strong>r<br />
Création d’une variable date en format<br />
Stata à partir <strong>de</strong> trois variables numériques<br />
soit le mois, le jour et l’année.<br />
generate p = uniform() Création <strong>de</strong> <strong>la</strong> variable p qui est tirée<br />
aléatoirement et comprise entre 0 et 1.<br />
generate z = invnorm (p) Affecte à <strong>la</strong> variable z, <strong>la</strong> valeur <strong>de</strong> <strong>la</strong><br />
variable aléatoire qui correspond à <strong>la</strong><br />
valeur p <strong>de</strong> <strong>la</strong> fonction <strong>de</strong> répartition <strong>de</strong> <strong>la</strong><br />
loi normale. Par définition, <strong>la</strong> fonction <strong>de</strong><br />
répartition d’une loi statistique varie <strong>de</strong> 0 à<br />
1. Ici, si p varie uniformément entre 0 et 1<br />
(ce qui est le cas du p <strong>de</strong> l’exemple<br />
précé<strong>de</strong>nt), z suit une loi normale centrée<br />
réduite. On utilise couramment cette<br />
procédure pour générer une variable<br />
artificielle qui suit une loi normale.<br />
On utilise help function pour obtenir <strong>la</strong> liste <strong>de</strong> toutes les fonctions disponibles.<br />
L’instruction egen offre également une série <strong>de</strong> possibilités qui permettent <strong>de</strong> créer<br />
rapi<strong>de</strong>ment <strong>de</strong>s variables qui <strong>de</strong>man<strong>de</strong>raient autrement plusieurs lignes d’instructions.<br />
egen [type] newvar = function(arguments) [if exp] [in range] [,<br />
options]<br />
Certaines fonctions génèrent <strong>la</strong> même constante pour toutes les observations (Hébert,<br />
2003, p. 17).<br />
egen min_x1 = min(x1) Prend <strong>la</strong> valeur minimum <strong>de</strong> x1<br />
egen max_x1 = max(x1) Prend <strong>la</strong> valeur maximale <strong>de</strong> x1<br />
egen sum_x1 = (x1) Somme <strong>de</strong> toutes les valeurs <strong>de</strong> x1<br />
egen med_x1 = median(x1) Valeur médiane <strong>de</strong> x1<br />
egen avg_x1 = mean(x1) Moyenne <strong>de</strong> x1<br />
egen sd_x1 = sd(x1) Écart-type <strong>de</strong> x1.<br />
Certaines fonctions génèrent une valeur différente pour chaque observation ou ligne.<br />
egen z_x1 = std(x1) Valeur standardisée <strong>de</strong> x1<br />
(soustraire <strong>la</strong> moyenne et diviser par