Stata Demo Version



This module will show how to use date variables, date functions, and date display formats in Stata.

  1. Current Stata Version
  2. Stata Download 16
  3. Stata 13 Free Download
  4. Stata Demo Versions
  5. Stata Download
  6. Stata Version 16

Converting dates from raw data using the 'date()' function

Download stata for windows 10 for free. Development Tools downloads - Stata 11 by StataCorp LP and many more programs are available for instant and free download. Stata trial version free download. Most people looking for Stata trial version free downloaded: Stata 11. 3.7 on 99 votes. Stata is a suite of applications used for data analysis, data management, and graphics. Stata Installation Qualification Tool. 3.4 on 27 votes.

Current Stata Version

See the documentation of bootstrap for more details about bootstrapping in Stata. If you want to be able to replicate your results you should set seed before calling psmatch2. The propensity score - the conditional treatment probability - is either directly provided by the user or estimated by the program on the indepvars.

The trick to inputting dates in Stata is to forget they are dates, and treat them as character strings, and then later convert them into a Stata date variable. You might have the following date data in your raw data file.

You can read these data by typing:

Using the list command, you can see that the date information has been read correctly into bday.

Since bday is a string variable, you cannot do any kind of date computations with it until you make a date variable from it. You can generate a date version of bday using the date() function. The example below creates a date variable called birthday from the character variable bday. The syntax is slightly different depending on which version of Stata you are using. The difference is in how the pattern is specified. In Stata 9 it should be lower case (e.g., 'dmy') and in Stata 10, it should be upper case for day, month, and year (e.g., 'DMY') but lower case if you want to specify hours, minutes or seconds (e.g., 'DMYhms'). Our data are in the order day, month, year, so we use 'DMY' (or 'dmy' if you are using Stata 9) within the date() command. (Unless otherwise noted, all other Stata commands on this pageare the same for versions 9 and 10.)

In Stata version 9:

Stata Demo Version

In Stata version 10:

Stata Demo Version

Let’s have a look at both bday and birthday.

The values for birthday may seem confusing. The value of birthday for John is 0 and the value of birthday for Mark is -207. Dates are actually stored as the number of days from Jan 1, 1960 which is convenient for the computer storing and performing date computations, but is difficult for you and I to read.

We can tell Stata that birthday should be displayed using the %d format to make it easier for humans to read.

The date() function is very flexible and can handle dates written in almost any manner. For example, consider the file dates2.raw.

These dates are messy, but they are consistent. Even though the formats look different, it is always a month day year separated by a delimiter (e.g., space slash dot or dash). We can try using the syntax from above to read in our new dates. Note that, asdiscussed above, for Stata version 10 the order of the date is declared in upper case letters (i.e., 'MDY') while forversion 9 it is declared in all lower case (i.e., 'mdy').

Stata was able to read those dates without a problem. Let’s try an even tougher set of dates. For example, consider the dates in dates3.raw.

Let’s try reading these dates and see how Stata handles them. Again, remember that for Stata version 10 dates are declared 'MDY' while for version 9 they are declared 'mdy'.

As you can see, Stata was able to handle almost all of those crazy date formats. It was able to handle Apr12,1990 even though there was not a delimiter between the month and day (Stata was able to figure it out since the month was character and the day was a number). The only date that did not work was Apr121990 and that is because there was no delimiter between the day and year. As you can see, the date() function can handle just about any date as long as there are delimiters separating the month day and year. In certain cases Stata can read all numeric dates entered without delimiters, see help dates for more information.

Stata

Converting dates from raw data using the mdy() function

In some cases, you may have the month, day, and year stored as numeric variables in a dataset. For example, you may have the following data for birth dates from dates4.raw.

You can read in this data using the following syntax to create a separate variable for month, day and year.

A Stata date variable can be created using the mdy() function as shown below.

Let’s format birthday using the %d format so it displays better.

Consider the data in dates5.raw, which is the same as dates4.raw except that only two digits are used to signify the year.

Let’s try reading these dates just like we read dates4.raw.

As you can see, the values for birthday are all missing. This is because Stata assumes that the years were literally 48, 60, 70 and 71 (it does not assume they are 1948, 1960, 1970 and 1971). You can force Stata to assume the century portion is 1900 by adding 1900 to the year as shown below (note that we use replace instead of generate since the variable birthday already exists).

Computations with elapsed dates

Date variables make computations involving dates very convenient. For example, to calculate everyone’s age on January 1, 2000 simply use the following conversion.

Please note that this formula for age does not work well over very short time spans. For example, the age for a child on their his birthday will be less than one due to using 365.25. There areformulas that are more exact but also much more complex. Here is an example courtesy of DanBlanchette.

Other date functions

Given a date variable, one can have the month, day and year returned separately if desired, using the month(), day() and year() functions, respectively.

If you’d like to return the day of the week for a date variable, use the dow() function (where 0=Sunday, 1=Monday etc.).

Summary

The date() function converts strings containing dates to date variables. The syntax varies slightly by version.

Stata Demo Version

In Stata version 9:

In Stata version 10:

The mdy() function takes three numeric arguments (month, day, year) and converts them to a date variable.

You can display elapsed times as actual dates with display formats such as the %d format.

Other date functions include the month(), day(), year(), and dow() functions. For online help with dates, type help dates at the command line. For more detailed explanations about how Stata handles dates and date functions, please refer to the Stata Users Guide.

Downloading Stata

Stata

Stata Download 16

Go to the Stata download site.


Stata 13 Free Download

You will be greeted with the following screen:

2. Input your username and password in the prompt. You received these in your email from StataCorp.
3. On the next screen, choose your operating system.

In this example, we have chosen a Windows installation.

Stata Demo Versions

4. Click on SetupStata16.exe.

Where did my download go? [Chrome] [Firefox][IE]

Stata Download

5. Double-click on SetupStata16.exe to begin the installation. When asked whether you want to run the file, click on Yes.

Stata Version 16

Next steps