New functions for handling of date values available in microdata.no

 by  Trond Pedersen

Through microdata.no, it is possible to extract/import and work with data on event format. This is the built-in raw format where each unit may be represented with several observations/records associated with change events. Each time a unit takes a new value for a given variable, this is represented as a new record containing the new value. Such datasets also have a set of start- and stop dates showing the start- and stop measurement for the new variable value.

Eventdata may be extracted/created by using the command import-event. A specification of measurement time interval is required, and the dataset will as a result consist of all records overlapping or within the specified interval. In addition to the variable itself, the dataset will also contain the start- and stop dates for all records, represented by a start- and stop variable. The following name convention is used: START@<variable name> and STOP@<variable name>.

The values of the date variables assosiated with the event data are presented with a so-called reference format, i.e. numerical values specifying the number of days from 01.01.1970. This makes it trivial to compute durations (number of days), as it is not necessary to take varying number of days in months or leap years into consideration: duration = stop date - start date

However, the reference format is not very intuitively in many situations. In order to solve this, a set of functions have been added which makes it possible to recalculate from reference values into year, month, week, weekday, quarter etc.

The following new functions are now available for recalculation purposes (input parameter is the name of the variable containing the start- or stop dates):

  • year() - convert into year
  • month() - convert into month
  • day() - convert into day of month
  • dow() - convert into weekday (1-7, 1 = monday, 2 = tuesday etc)
  • doy() - convert into day of year (1-366)
  • week() - convert into week number
  • quarter() - convert into quarter
  • halfyear() - convert into halfyear
  • isoformatdate() - convert into date format YYYY-MM-DD (string)

Click here for more details about the new date functions (go to Appendix B, page 104-107 in the User Guide)