Richard Williams replied to Paul O'Brien
> >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?
> . 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)
In addition, an -egen- function -ncyear()- is bundled
in -egenmore- on SSC.
Nick
[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/