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: Need help for calculation across observations within variable
From
Michael Stewart <[email protected]>
To
statalist <[email protected]>
Subject
st: Need help for calculation across observations within variable
Date
Tue, 21 May 2013 09:17:15 -0400
HI,
I am looking to see if anyone could an efficient code than what I have
been using for a particular issues that I am dealing with
My Need
1)Create a variable which shows if the "year" is same or different by pat_name
2)Create a variable which shows number of distinct years ,per patient
My dataset structure is as follows
pt_name year(string variable)
111 2009
111 2009
111 2009
111 2011
222 2009
222 2009
222 2010
My code is two step one
Step-1: bysort pt_name(year): gen flag=_n==_N
Step-2:egen max=total(flag),by(pt_name)
Please let me know if there is an more efficient one step code
--
Thank you ,
Yours Sincerely,
Mike.
*
* 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/