Statalist The Stata Listserver


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

RE: st: how to keep first four figures of a variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: how to keep first four figures of a variable
Date   Sun, 9 Jul 2006 17:47:49 +0100

If these are dates, they are run-together and the Stata official date functions 
won't help much. You need either similar tricks to that below or something 
like -todate- from SSC (which just uses similar tricks to that below). 

Nick 
n.j.cox@durham.ac.uk 

Philipp Rehm
 
> This may work:
> gen new=real(substr(string(original),1,4))
> 
> (I don't know how hypothetical your numbers are, but if your variable
> "original" reports dates, check out -help date functions- to extract,
> say, the year).
 
> FUKUGAWA, N. wrote:

> > I would like to make a change in a variable.
> > A new variable keeps only first four figures of ten-digit variable.
> > 
> > original -> new
> > 1980000123 -> 1980
> > 1996123456 -> 1996
> > 
> > How do I generate such variable using 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/



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