Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: generate variable equal to first non-zero value in row
From
D-Ta <[email protected]>
To
[email protected]
Subject
st: generate variable equal to first non-zero value in row
Date
Wed, 21 Aug 2013 17:25:36 +0200
Dear Statausers,
I have a dataset with the variables id and and out1-out5 where the "out"
variables represent sequential outcomes. I would like to generate a
variable (in the example below named first_nonzero) which indicates the
first outcome in the sequence row that is non zero. If there are all
zeros throughout, that indicator variable should be set/remain missing.
The following table illustrateswhat I am trying to do. How do I generate
the first_nonzero variable? (I was trying to work with the -egenmore-
commands, but couldnt figure out).
id out1 out2 out3 out4 out5 first_nonzero
1 0 0 0 2 2 2
2 0 2 2 0 0 2
3 0 0 0 0 0 .
4 4 4 4 0 0 4
5 3 0 2 2 2 3
6 0 4 4 4 0 4
Many thanks,
Darjusch
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/