Announcement

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

  • Creating Panel Data from Start Month and End Month

    I have a data set in the following format:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str33 customername str42 subscription float(monthly_payment first_month last_month)
    "John" "A" 339 723 729
    "John" "B" 300 731 747
    "Pete" "C"  99 732 736
    "Pete" "D"  99 733 742
    end
    format %tmMonthCCYY first_month
    format %tmMonthCCYY last_month
    I would like to turn this into panel data based on the first month and last month, with the group variable being "subscription" and one row per subscription-month. Customername and monthlypayment would be the same for each month for each subscription. Any help would be greatly appreciated.

    Desired output (for just the first subscription for simplicity's sake):

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str33 customername str42 subscription float(monthly_payment month)
    "John" "A" 339 723
    "John" "A" 339 724
    "John" "A" 339 725
    "John" "A" 339 726
    "John" "A" 339 727
    "John" "A" 339 728
    "John" "A" 339 729
    
    end
    format %tmMonthCCYY month
    Thanks!

  • #2
    Code:
    expand last_month - first_month + 1
    by customername subscription, sort: gen mdate = first_month + _n - 1
    format mdate %tmMonthCCYY
    drop first_month last_month

    Comment

    Working...
    X