Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Year to start 1st April


From   Richard Williams <Richard.A.Williams.5@nd.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Year to start 1st April
Date   Fri, 05 Mar 2004 23:20:36 -0500

At 12:19 AM 3/6/2004 +0000, Paul O'Brien wrote:
Hi,

gen year= year( datevisit) gives me the calendar year of the clinic visit. How do I get the financial year of the visit, starting on the 1st April each year?

Thanks for help.

Paul
Whoops. I think the original solution I posted quickly gets off a day. I think it is fixable, but how about this instead:

. gen finyear = year(datevisit)

. replace finyear = finyear - 1 if month(datevisit) < 4
(8 real changes made)

. list, separator(4)

+-----------------------------------------+
| datevi~t month day year finyear |
|-----------------------------------------|
1. | 89 3 30 1960 1959 |
2. | 90 3 31 1960 1959 |
3. | 91 4 1 1960 1960 |
4. | 92 4 2 1960 1960 |
|-----------------------------------------|
5. | 454 3 30 1961 1960 |
6. | 455 3 31 1961 1960 |
7. | 456 4 1 1961 1961 |
8. | 457 4 2 1961 1961 |
|-----------------------------------------|
9. | 9220 3 30 1985 1984 |
10. | 9221 3 31 1985 1984 |
11. | 9222 4 1 1985 1985 |
12. | 9223 4 2 1985 1985 |
|-----------------------------------------|
13. | 16160 3 30 2004 2003 |
14. | 16161 3 31 2004 2003 |
15. | 16162 4 1 2004 2004 |
16. | 16163 4 2 2004 2004 |
+-----------------------------------------+

If instead you want April 1 to be the start of the next year (e.g. April 1, 2003 is the beginning of financial year 2004) change the coding to

. gen finyear = year(datevisit)

. replace finyear = finyear + 1 if month(datevisit) > 3
(8 real changes made)

. list, separator(4)

+-----------------------------------------+
| datevi~t month day year finyear |
|-----------------------------------------|
1. | 89 3 30 1960 1960 |
2. | 90 3 31 1960 1960 |
3. | 91 4 1 1960 1961 |
4. | 92 4 2 1960 1961 |
|-----------------------------------------|
5. | 454 3 30 1961 1961 |
6. | 455 3 31 1961 1961 |
7. | 456 4 1 1961 1962 |
8. | 457 4 2 1961 1962 |
|-----------------------------------------|
9. | 9220 3 30 1985 1985 |
10. | 9221 3 31 1985 1985 |
11. | 9222 4 1 1985 1986 |
12. | 9223 4 2 1985 1986 |
|-----------------------------------------|
13. | 16160 3 30 2004 2004 |
14. | 16161 3 31 2004 2004 |
15. | 16162 4 1 2004 2005 |
16. | 16163 4 2 2004 2005 |
+-----------------------------------------+



-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: Richard.A.Williams.5@ND.Edu
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc

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