Our data are in the order day, month, year, Year (e.g., "DMY") but lower case if you want to specify hours, minutes or In Stata 9 it should be lowerĬase (e.g., "dmy") and in Stata 10, it should be upper case for day, month, and Theĭifference is in how the pattern is specified. Slightly different depending on which version of Stata you are using. The example below creates a date variable calledīirthday from the character variable bday. You can generate a date version of bday using the date() function. Since bday is a string variable, you cannot do any kind of date computations with it until you make aĭate variable from it. Using the list command, you can see that the date information has been read correctly into You can read these data by typing: infix str name 1-4 str bday 6-17 using dates1.raw (4 observations read) You might have the following date data in your raw data file. Them as character strings, and then later convert them into a Stata date The trick to inputting dates in Stata is to forget they are dates, and treat Of the year.This module will show how to use date variables, date functions, and date display formats in Stata.Ĭonverting dates from raw data using the "date()" function Here we graph just the data for the first half We can use if tin() to specify a range of date values that The tline() option also understands that the x axis isĬomposed of dates and can be used to place lines at particular dates. graph twoway tsline high low, tlabel(01apr2001 01jul2001 01oct2001, format(%tdmd) ) Here we change the format of the date to be month and day. Option where we can supply in valid format that we would supply We can change the format of the display of the date variable using the format() graph twoway tsline high low, tlabel(01apr2001 01jul2001 01oct2001) Ttick(), tmlabel(), tmtick(), and tscale(), seeĭetails. Other options that can be used in a similar way include For example, say that we wanted the x axis to be labeled Understand that the x axis is a date variable and are much easier to In addition to these benefits, there are options we can use that Next, note that the labels for the xĪxis are labeled much better with more logical values having been chosen. This is because Stata knew, from the tsset command, what the time Note that we did not need to specify date in the command. Now we can use graph twoway tsline to graph the data. Time variable: date, 02jan2001 to 31dec2001, but with gaps To tell Stata that the variable date represents time and that its Graph twoway line we can use graph twoway tsline which is specifically designed for making line graphs where the Labeling the x axis since these are date values. Also, it could be difficult to change the values Properly labeled with the dates, but the selection of the values labeling thisĪxis could be better. We could use the graph twoway line command to graph the high and low closing price for the year, as shown below. High and low trading price for a given day and date which is a date This file has variables like high and low that represents the This data file contains data for all of the trading days in 2001. This FAQ shows examples of graphing data where the x axis represents dates.įor these examples, we will use the sp500 dataįile that comes with Stata and we can use it via the sysuse command.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |