Sorry, Gaby, I was not particularly careful with the syntax, just
wanted to communicate the idea. To be more precise, the resulting
variable is a string, so "min" does not work with it. So, first we
need to:
destring newdate1, generate(nd1)
Now nd1 is a numeric variable. And second, don't write the parenthesis
() after by:
by CODE: egen m=min(nd1)
. l
+----------------+
| CODE newdate |
|----------------|
1. | 10 0410 |
2. | 10 0414 |
3. | 10 0408 |
4. | 10 0301 |
5. | 20 0208 |
|----------------|
6. | 20 0216 |
7. | 20 0208 |
8. | 20 0210 |
+----------------+
+----------------------------+
| CODE newdate nd1 beg |
|----------------------------|
1. | 10 0301 301 301 |
2. | 10 0408 408 301 |
3. | 10 0410 410 301 |
4. | 10 0414 414 301 |
5. | 20 0208 208 208 |
|----------------------------|
6. | 20 0208 208 208 |
7. | 20 0210 210 208 |
8. | 20 0216 216 208 |
+----------------------------+
Best regards,
Sergiy
PS: Nice photos!
On 10/8/07, Ana Gabriela Guerrero Serdan <[email protected]> wrote:
> Dear Sergiy,
>
> Thanks, I managed to swap the month first and then the
> day. But when trying to calculate the minimum it says
>
> by(CODE): egen beg=min(newdate1)
> invalid syntax
> r(198);
>
> I been trying to calculate the mimimum of newdate
> without the sort and its also not possible... !?
> Should I firs set the var as date?
>
>
> Gaby
>
> --- Sergiy Radyakin <[email protected]> wrote:
>
> > Hello Ana Gabriela,
> >
> > this will swap the day and month in the [string]
> > variable Date1:
> > gen newdate1=substr(Date1,3,2)+substr(Date1,1,2)
> > As long as Date2 is always later than Date1, you
> > care only about Date1
> > for the minimum:
> > sort CODE newdate1
> > by(CODE): egen beg=min(newdate1)
> >
> > Quite similarly you proceed to the end dates.
> >
> > Best regards,
> > Sergiy Radyakin
> >
> >
> > On 10/8/07, Ana Gabriela Guerrero Serdan
> > <[email protected]> wrote:
> > > Dear all,
> > >
> > > I have a very basic question but I havent find the
> > > date commands when I only have day and month.
> > >
> > > I have information on interviews carried out and
> > want
> > > to know the range of interview per province
> > (CODE), so
> > > I want to calculate the min and max of the dates
> > > within each province.
> > >
> > >
> > > . list CODE Date1 Date2 Date3
> > >
> > > +-------------------------------+
> > > | CODE Date1 Date2 Date3 |
> > > |-------------------------------|
> > > 1. | 01 2704 |
> > > 2. | 01 2704 3004 |
> > > 3. | 01 2704 1505 |
> > > 4. | 01 2505 |
> > > 5. | 01 2605 |
> > > |-------------------------------|
> > > 6. | 02 2705 0106 |
> > > 7. | 02 2805 0606 |
> > >
> > > etc..
> > >
> > > Can anyone help?
> > >
> > > thanks,
> > > Gaby
> > >
> > >
> > >
> > >
> > >
> >
> ____________________________________________________________________________________
> > > Tonight's top picks. What will you watch tonight?
> > Preview the hottest shows on Yahoo! TV.
> > > http://tv.yahoo.com/
> > >
> > > *
> > > * 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/
> > >
> > *
> > * 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/
> >
>
>
> Gaby Guerrero Serdan
>
> Deparment of Economics
> Royal Holloway, University of London
> TW20 OEX
> Egham, Surrey
> England, UK
> http://www.rhul.ac.uk/economics/About-Us/postgrads.html
> http://www.flickr.com/photos/49939890@N00/
>
> Tel: +41788502082 (in switzerland)
>
>
>
> _
>
*
* 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/