Announcement

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

  • Monthly last observation in a temporal series

    Hi, I have a temporal series with the follow variables: idcompany, lastprice and date (dd/mm/yyyy). I have set variable date as temporal series data and idcompany my Panel Id Variable. So, I need generate another dataset with only the last price in each month of each company. How can I do it?

  • #2
    Code:
    gen mdate = mofd(date)
    bysort idcompany mdate (date) : keep if _n = _N

    Comment


    • #3
      N.B. It is not clear in #1 whether the currently existing date variable is a string formatted dd/mm/yyyy or a Stata internal format date variable with display format %tdDD/NN/CCYY. If the former, you will first need to convert it to the latter, using the -daily()- function, before you can use Nick's code.

      Comment


      • #4
        To me #1 implied some use of tsset or xtset, not possible unless the date variable is numeric.

        Comment


        • #5
          Good point, Nick.

          Comment


          • #6
            Hi, I solved my issue with commands below using the same dataset. Stata is totally new for me.

            gen long first_of_next_month = dofm(mofd(mypricedate)+1

            keep if mypricedate + 1 == first_of_next-Month

            Thanks a lot!

            Comment


            • #7
              Thanks for showing your solution. I think you left off a closing ) character in your -gen- command. Shouldn't it be
              [code]
              gen long first_of_next_month = dofm(mofd(mypricedate))+1

              Comment


              • #8
                Oh, yes, of course, Thanks!

                Comment

                Working...
                X