The name is absent



Stata Technical Bulletin


STB-20


dm20 Date functions


Alan Riley, Stata Corporation, FAX 409-696-4601

Since the publication in the STB of A library of time series programs (see sts7.3 below), Stata Corp. has received numerous
requests for additional commands to manipulate dates. One request in particular piqued our interest and led to the development
of the commands described below. The user in question maintains Stata data sets of daily financial data which are collapsed
to create monthly averages and then used to generate financial forecasts. The Stata commands used to calculate these averages
and forecasts are stored in do-files that are executed automatically (they are executed as cron jobs on a Unix system). The user
wanted to make sure only full months of daily data were used; if the most recent month was not yet over, the user wanted to
discard its data.

This is a more subtle problem than it first appears. How can we tell in a do-file if the last observation comes from the last
day of the month? We wrote lastday to answer this question. But the problem isn’t solved yet. The last day of the month may
fall on a weekend. How can we tell if the last observation falls on the last business day of the month? Iastbday addresses this
question. Now, when a forecast is produced, how can we distinguish the historical observations from the projections? One way
is to compare the observation date to today’s date. Hence, the today command.

I hope the following commands will satisfy many of your requests. I am particularly interested in hearing from users about
other date-related problems for which Stata may not yet provide a ready solution. Any other comments or suggestions that you
have concerning these date-conversion programs are also appreciated.

New date commands

downame dowvar, generate (dvwar)

namedow dayvar, generat e(dowvar)

mnthname mvar, generate mnthaar)
namemnth mthvar, generate (mvar)

mdytodow mvardvaryvar, generate (dowv`ar)

lastday mvaryvar, genera,te(dvar)

Iastbday mvaryvar, generate(dvar)

ystrday mvar dvaryvar, generate (mvar dvaryvar)

today, generatemnaardvaryvar)

where

dayvar string variable containing day (Sunday-Saturday)
mthvar string variable containing month (January-December)
dowvar, dvar mvar, and yvar are defined as in [5d] dates.

These commands perform various date conversions. downame converts a numeric day of week to the corresponding name.
namedow performs the opposite conversion. Likewise, mnthname converts a numeric month to the corresponding name, and
namemnth performs the opposite conversion. mdytodow calculates the numeric day of the week from the month, day, and year.
lastday calculates the last calendar day for a given month and year, while Iastbday calculates the last business day for a
particular month and year. (“Business day” is defined as a day from Monday through Friday. Holidays are not taken into account).

ystrday calculates the previous month, day, and year given any month, day, and year. today simply reads the S-DATE
global macro (see [2] macros) and generates variables containing the current month, day, and year.



More intriguing information

1. A model-free approach to delta hedging
2. Lumpy Investment, Sectoral Propagation, and Business Cycles
3. Retirement and the Poverty of the Elderly in Portugal
4. The name is absent
5. The name is absent
6. The Shepherd Sinfonia
7. Importing Feminist Criticism
8. Evidence-Based Professional Development of Science Teachers in Two Countries
9. 09-01 "Resources, Rules and International Political Economy: The Politics of Development in the WTO"
10. The name is absent
11. Migration and employment status during the turbulent nineties in Sweden
12. The name is absent
13. Initial Public Offerings and Venture Capital in Germany
14. The name is absent
15. Estimating the Technology of Cognitive and Noncognitive Skill Formation
16. The Shepherd Sinfonia
17. The name is absent
18. Commuting in multinodal urban systems: An empirical comparison of three alternative models
19. Valuing Access to our Public Lands: A Unique Public Good Pricing Experiment
20. Migrating Football Players, Transfer Fees and Migration Controls