Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: creating variable


From   P chrisman <[email protected]>
To   Stata List <[email protected]>
Subject   st: creating variable
Date   Wed, 06 Jun 2007 13:19:36 -0700

Dear List,

I have a longitudinal data set with 12 records for each subject for a take home final exam. I need to create an average iron dose measurement for the first months of the 12 months study period. I have tried the following in long format:

gen ironm1=iron if month==1
(11132 missing values generated)

. gen ironm2=iron if month==2
(11134 missing values generated)

. gen ironm3=iron if month==3
(11135 missing values generated)

. gen ironBL=( ironm1+ ironm2+ ironm3)/3
(12144 missing values generated)

The problem is that my ironBL variable is "missing" data for all subjects rather than the average of the 3 iron measurements.

I also tried the following in wide format:

gen ironBL=(iron1+iron2+iron3)/3
(4 missing values generated)

I honestly do not understand what went wrong here. I thought perhaps egen ironBL=mean(iron) if month<=3, but that does not work either.

Thanks,
peggy

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index