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]
Re: st: Repeated matching of variables
From
Steve Samuels <[email protected]>
To
[email protected]
Subject
Re: st: Repeated matching of variables
Date
Sun, 28 Jul 2013 22:24:37 -0400
One way:
*************CODE BEGINS*************
clear
input str10 group str10 id str10 date
group1 id1 date1
group1 id2 date2
group1 id3 date3
group2 id4 date4
group2 id5 date5
group2 id6 date6
end;
levelsof group, local(g)
save d01, replace
clear
save d02, emptyok replace
foreach i of local g {
use d01, clear
keep if group =="`i'"
fillin id date
replace group="`i'"
append using d02
save d02, replace
}
sort group id date
list, sepby(group)
**************CODE ENDS**************
Steve
[email protected]
On Jul 28, 2013, at 2:12 PM, Jingjing Xia wrote:
Hi Statalist~
I want to repeatedly match variable "id" to "date" by "Group", but can't figure out how to exactly to it....To be more specific:
My dataset is in the format:
Group1 id1 date1
Group1 id2 date2
Group1 id3 date3
Group2 id4 date4
Group2 id5 date5
Group2 id6 date6
And I want to have something like this:
date1 id1
date1 id2
date1 id3
date2 id2
date2 id3
date3 id3
date4 id4
date4 id5
date4 id6
date5 id5
date5 id6
date6 id6
Can anyone help? Thank you so much!
Best
Jingjing
*
* 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/
*
* 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/