Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Is there a command for picking off the lowest values of an Identified group?

From   Neil Shephard <>
Subject   Re: st: Is there a command for picking off the lowest values of an Identified group?
Date   Thu, 29 Jul 2010 15:49:33 +0000

On Thu, Jul 29, 2010 at 3:43 PM, Ian Breunig <> wrote:
> I want to find the age of the mother's youngest child.
> If, for example, I have data as follows:
> Mother ID:        Child ID:     Child Age:
> 1                         a                  1
> 1                         b                  2
> 1                         c                  3
> 1                         d                  4
> 2                         e                  10
> 2                         f                   10
> 2                         g                  12
> 3                         h                  5
> 3                         i                   7
> Is there a simple command to tell me the youngest age for every Mother
> ID or  do I have to use a do loop and if statement to do this?  If so
> can anyone help me out with the most efficient way to code the do
> loop.

No loop required, the following should do what you are after (note
I've assumed variable names, as the above are illegal in Stata as
spaces in variable names are not permitted)

bysort mother_id (child_age) : gen youngest_child = child_age[1]

The variable youngest_child will be constant within each grouping of
mother_id and will contain the age of the youngest child (by virtue of
having sorted the data on that variable).


"... no scientific worker has a fixed level of significance at which
from year to year, and in all circumstances, he rejects hypotheses; he
rather gives his mind to each particular case in the light of his
evidence and his ideas." - Sir Ronald A. Fisher (1956)

Email -
Website -
Photos -

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index