Statalist The Stata Listserver


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

Re: st: RE: creating variable


From   P chrisman <[email protected]>
To   [email protected]
Subject   Re: st: RE: creating variable
Date   Wed, 06 Jun 2007 13:42:52 -0700

Thanks for the help! The exam is indeed mine and you can share in my A!!
Peggy

Nick Cox wrote:
The nub of the problem is this. Consider these data:
month sales (sales of Stata 10) 1 1 million
2 1 billion 3 1 trillion
Then
gen sales1 = sales if month == 1 gen sales2 = sales if month == 2 gen sales3 = sales if month == 3
creates these variables
month sales1 sales2 sales3 1 1 million . . 2 . 1 billion . 3 . . 1 trillion

Now when you average, your averages will be all
missing, as they are all based on the sum of one value and two missings, which in Stata is missing. You are averaging across observations. You need
to average in columns.
Check out, for example, -tssmooth-.
(If the take home exam is yours, do I get to share
your grade?)
Nick [email protected]
P chrisman

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.

*
* 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/
*
*   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