![]() We have already learnt several useful applications of the egen command here. Reg gdp L.gdp L.unemployment L2.unemployment, vce(robust) notations directly in the list of variables for regression without creating them first. If we want to create differences we just need to combine what we learnt: Data must be sorted first, in order by time for time-series data. Future values work the same with F.t F2.t ecc. The value two units of time ago is L2.t where L stands for lag. It creates the value of the variable t one unit of time ago. ![]() In order to refer to past and future data, Stata has two useful commands that are L and F. Tsset timevar // Tells Stata you have time series data with the time listed in the variable timevar. You are already familiar with the syntax: With these two formulas you have created a single time variable time from separate year and month variable and you have displayed the values in a format like “2015m5”.įinally, you must declare your data as time series in order to use time-related commands. What if you have a year variable and a month one and need to combine them to obtain a single time variable? Again, straightforward! Just type: ![]() NB: All these date functions require a way to separate the parts so date like “20150401” are not allowed. You can play with this option putting the order you prefer like “my”, “ymd” and so on. The “mdy” option tells Stata the ordering of the month, day and year in the variable. I just told Stata to create a variable time, starting from a variable “dstr” that contains dates like “Dec-25-2013” or “25-1-2013”. You may say this is not widespread but trust me, several databank as World Bank provides data in a string format. If you have a string variable that describes the date for each observation and you want to convert it into a numeric format you can rely on Stata’s date conversion functions. Inside the parentheses, you have to type a year followed by a separator (a comma, colon or word) followed by a second number that specifies the day, week, month or quarter of that year. You may use the w() for week, m() for month and h() for half-year functions. NB: Please note that every syntax follows the same structure. Format tells Stata to display values of one selected variable in a given format among those available. This is a bit tricky! Indeed, we have created a variable that increases by 1 quarter in each observations but the result is an integer number increasing by 1 for each quarter (1990 quarter 2 is specified as 1, 1990 quarter 3 is specified as 2, etc).Īnother useful command in Stata is format. If you want to create a quarter variable instead, you can type something like: Your data should be properly sorted in the right order before! ![]() In this way, we have created a new variable Year, which begins with 1990 in the first observation and increases by 1 thereafter. If you don’t have a time variable in your data that are already in order and without gaps, you might create a year/quarter/day variable just typing: Your time variable should be an integer and usually should not have gaps between numbers. Creating a Time VariableĪ common issue we face when we manage time variables is that we must understand how to convert data from some other format, like a month-year string, into a single time variable. Today we are going to learn how to create a time variable, its lags, leads and differences. We already know that, when dealing with panels, we must inform Stata what variables measure time and individuals in the sample. Today I am going to start from the origins. That is why I need you to read carefully what I write and correct me if there is any mistake! I can correct myself just if you help me so, please, do it. I will come back on econometrics sometimes but it feels good to vary a bit! Moreover, this topic is and will be a true challenge for me because, I must confess, I have always used Matlab to deal with time series data and I am now learning practically how to do the same in Stata. I am glad to announce that I moved forward to time series analysis. Let’s discover the world of time series data with Stata. ![]()
0 Comments
Leave a Reply. |