Hi All
I've been trying to study relationships between the following three variables, one of which is slightly unusual; the 'labtest' variable indicates various tests conducted for a patient during a clinic visit. Ideally, the single 'labtest' variable below would be several different variables, each one for particular test such as BMI, pH, cholesterol etc. This is a panel (longitudinal) dataset where a subject can have between 1 and 12 clinic visits. Ethnicity and labtest are categorical variables with ethnicity having four categories and labtest having five categories (coded 1 to 5) indicating the the kind of test run.
If I wanted to find out the mean bmi by ethnic group (above is just a snap shot of three subjects), I tried the following:
However, the above does not return what I'm looking for. How does one get what I'm after?
A second question: How would I go about creating a new variable BMI by extracting BMI values from the 'labtest' and 'labtestvalue' variables as follows. The labtest indicates which subject has a recorded BMI and the labtestvalue provides the actual value.
Thanks!
/Amal
I've been trying to study relationships between the following three variables, one of which is slightly unusual; the 'labtest' variable indicates various tests conducted for a patient during a clinic visit. Ideally, the single 'labtest' variable below would be several different variables, each one for particular test such as BMI, pH, cholesterol etc. This is a panel (longitudinal) dataset where a subject can have between 1 and 12 clinic visits. Ethnicity and labtest are categorical variables with ethnicity having four categories and labtest having five categories (coded 1 to 5) indicating the the kind of test run.
Code:
ID ethnicity labtest labtestvalue 1 white bmi 22 1 white pH 6.4 1 white tsh 12 1 white chol 18 2 mixed bmi 23 2 mixed pH 7.4 2 mixed tsh 18 3 indian bmi 26 3 indian pH 4.3 3 indian tsh 18 3 indian chol 21 3 indian height 182
Code:
tabstat labtestvalue, by(ethnicity) stat(mean sd n), if labtestvalue==1
A second question: How would I go about creating a new variable BMI by extracting BMI values from the 'labtest' and 'labtestvalue' variables as follows. The labtest indicates which subject has a recorded BMI and the labtestvalue provides the actual value.
Code:
ID ethnicity labtest labtestvalue bmi 1 white bmi 22 22 1 white pH 6.4 22 1 white tsh 12 22 1 white chol 18 22 2 mixed bmi 23 23 2 mixed pH 7.4 23 2 mixed tsh 18 23 3 indian bmi 26 26 3 indian pH 4.3 26 3 indian tsh 18 26 3 indian chol 21 26 3 indian height 182 26
/Amal
Comment