Unknown <[email protected]> writes,
> Could anyone please help me with one of the questions?
>
> Var1- Storage type str8, display format %9s. It has
> month and year only like: 06/2005 .
>
> I want to
> 1- change the format to time,
> 2- add day dd/mm/yyyy, and
> 3- set dd for 15 like say: 15/05/2005.
I created an example dataset:
. list
+----------+
| original |
|----------|
1. | 06/2005 |
2. | 09/2006 |
+----------+
Variable original is str8.
Here's one solution:
. gen long newvar = date(original, "MY")
. format newvar %td
. list
+----------------------+
| original newvar |
|----------------------|
1. | 06/2005 01jun2005 |
2. | 09/2006 01sep2006 |
+----------------------+
Variable newvar is a -long-. If we wanted newvar to display as
01/06/2005 and 01/09/2005, we would specify format %tdDD/NN/CCYY
rather than %td.
. format newvar %tdDD/NN/CCYY
. list
<output omitted>
To shift newvar 14 days forward:
. replace newvar = newvar+14
(2 real changes made)
. list
+-----------------------+
| original newvar |
|-----------------------|
1. | 06/2005 15/06/2005 |
2. | 09/2006 15/09/2006 |
+-----------------------+
See -help dates and times-.
-- Bill
[email protected]
*
* 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/