Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: sorting and referencing

From   jean ries <>
Subject   Re: st: sorting and referencing
Date   Thu, 22 Dec 2005 12:30:20 +0100


I will assume that your data are in appropriate numeric format (c.f. the reply by Keith Dear). Then, you can generate the pattern variable as follows:

. g one = start_m < start_f
. g two = finish_m < start_f
. g three = start_f < finish_m
. g four = finish_f < finish_m
. egen pattern = concat(one two three four)
. replace pattern = subinstr(pattern, "1", "M", .)
. replace pattern = subinstr(pattern, "0", "F", .)

These few lines will work in the presence of "special cases" like missing values, ties and start/finish at the same time. However, these cases are handled in a particular way. So it's up to you to amend the code such that these special cases are handled the way you want.

Hope this helps,


Date: Wed, 21 Dec 2005 16:24:40 -0500
From: "Paley, Irina" <>
Subject: st: sorting and referencing

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

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index