Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with the Lag-Operator in time-series

    Hello,

    I'm currently working with time series and I need lags for my calculations. Unfortunately the lag Operator (L.) is not working, whereas [_n-1] does.

    Could you please help me with this issue? Sorry for my english and just let me know if u need further/other information (first post in this Forum).


    Thank you in advance!

    Code:
    tsset Date
            time variable:  Date, Dec 1989 to Dec 2018, but with  gaps
    
    
    gen USCPIinflationrate_lag2=L.USCPIinflationrate
    (349 missing values generated)
    
    gen USCPIinflationrate_lag= USCPIinflationrate[_n-1]
    (1 missing value generated)
    The table looks like this:
    Click image for larger version

Name:	Stata.jpg
Views:	1
Size:	14.6 KB
ID:	1528243


  • #2
    Unfortunately, the screenshot of data you show does not contain the information to be completely certain of what I'm going to say. Please don't do that again. Use -dataex-. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    I suspect your problem is that you expect -tsset- to recognize your dates as montly dates and interpet lage to mean 1 month earlier. But perhaps they are not true Stata monthly internal format dates. It is impossible to tell from a screenshot as the display format can make anything look like anything else. If you post back showing the example data with -dataex-, it will be quite clear what is going on and you can get concrete, specific help.

    Comment


    • #3
      Thank you for helping me to better formulate and structure my questions (with dataex) in the future Mr.Schechter. I've figured it out for this small dataset.
      Indeed it was a issue with the time formatting.


      Comment

      Working...
      X