[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Ernest Berkhout <ernestb@seo.fee.uva.nl> |

To |
statalist@hsphsun2.harvard.edu, <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: RE: The last four digits |

Date |
Tue, 09 Dec 2003 10:58:42 +0100 |

At 01:41 9-12-2003, Daniel R Sabath wrote:

That is not a completely foolproof solution, as I don't think that the default behaviour for float-variables will be to display leading zero's. The second line is sufficient to extract the 4 last digits, as was the problem at hand.I just wrote some code for this for someone else, so it's fresh on the brain. /* assumes nacimi is numeric and of fixed length */ gen nacimi-1 = real(substr(string(nacimi),1,4)) gen nacimi-2 = real(substr(string(nacimi),-4,4))

But to elaborate a bit on this, if the objective would be to split something like the following variable:

1041974

1051973

17041975

where you want the last 4 digits in a variable "year" and the remaining part in a variable "date" an alternative to the substr-string-approach is as follows:

gen date = int(nacimi/10000)

gen year = mod(nacimi/10000)

There is no restriction as to how many digits there are before the last 4 digits.

Ernest Berkhout

SEO Amsterdam Economics

University of Amsterdam

Room 3.08

Roetersstraat 29

1018 WB Amsterdam

The Netherlands

tel.:+ 31 20 525 1657

fax:+ 31 20 525 1686

http://www.seo.nl

===========================

A statistician: someone who insists

on being certain about uncertainty

===========================

*

* 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/

**Follow-Ups**:**Re: st: RE: The last four digits***From:*David Kantor <dkantor@jhu.edu>

**References**:**st: The last four digits***From:*"jtuesta" <jtuesta@agrario.minag.gob.pe>

**st: RE: The last four digits***From:*"Daniel R Sabath" <sabathd@u.washington.edu>

- Prev by Date:
**st: RE: The last four digits** - Next by Date:
**st: RE: matrix of variable averages** - Previous by thread:
**st: RE: The last four digits** - Next by thread:
**Re: st: RE: The last four digits** - Index(es):

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