Hi Irinia, here are a couple of ways... they assume the times are in
24-hour numeric format (you would need to do some messing about with
string functions otherwise). I have ignored the tricky bits: what
result you want (a) when the time taken could be 0 hours (b) when two
times are the same.
Keith
clear
tempfile patterns
input byte pattern str4 sequence
0 MMFF
2 MFMF
3 MFFM
4 FMMF
5 FMFM
6 FFMM
end
sort pattern
save `patterns', replace
clear
input household m_start m_stop f_start f_stop
1 5 15 15 22
2 7 14 8 16
3 8 17 21 4
4 1 4 2 3
5 2 3 1 4
6 2 4 1 3
7 3 4 1 2
end
replace m_stop=m_stop+24 if m_stop<m_start // finished task the next day
replace f_stop=f_stop+24 if f_stop<f_start // maybe needs <= ?
gen byte
pattern=2*[(f_start<m_start)+(f_start<m_stop)]+(f_stop<m_start)+(f_stop<m_stop)
sort pattern
merge pattern using `patterns', nokeep
drop _merge pattern
sort household
list
* or you could do it like this, more pedestrian perhaps. No doubt I
should use temp names.
rename m_start t1
rename m_stop t2
rename f_start t3
rename f_stop t4
reshape long t, i(household) j(j)
sort household t
gen str1 sex="M"
replace sex="F" if j>2
egen order=seq(), by(household)
drop j t
reshape wide sex, i(household) j(order)
gen str4 sequence=sex1+sex2+sex3+sex4
drop sex?
list
At 08:24 AM 22/12/05, you wrote:
Dear stata list servers,
Could I ask you for help on a creative solution to the following
task, that I seem to find a little unusual (maybe there is an
obvious answer to this?)
Suppose each household consists of a male and a female, and I have
data on the time they record doing a certain task.
The data looks like this:
Start task, Male Finish
task, Male Start task, Female Finish
task, Female
household
1 5am 3pm
5pm 10pm
household
2 7am 2pm
8am 4pm
household
3 8am 5pm
9pm 4am
I want to sort, within each household, all numbers in ascending
order (time increasing as we move to the right), so that the data
looks like this:
Start task, Male
household
1 5am 3pm
5pm 10pm
household
2 7am 8am
2pm 4pm
household
3 8am 5pm
9pm 4am
...And then substitute each time by who it refers to (the male
starting or finishing, or the female, so that it looks like this:
Household id Timing pattern
household 1: MMFF
household 2: MFMF
household 3: MMFF
How would I do that?
Thanks so much for any help you can provide!
Irina
*
* 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/
==========================================================
Dr Keith B.G. Dear
Senior Fellow in Biostatistics
National Centre for Epidemiology and Population Health (NCEPH)
The Australian National University
Canberra, ACT 0200, Australia
Tel: 02 612 54865, Fax: 02 612 50740
http://nceph.anu.edu.au/Staff_Students/staff_pages/dear.php
CRICOS provider #00120C
*
* 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/