Announcement

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

  • Expand year for every city (Panel dataset)

    Hi all,

    I have a panel dataset where I have a city and the year. However, for some cities I only have one year (e.g., Madrid - 1960). I would like to extend it such that I have one observation every year for Madrid between 1960 and 2013 i.e. Madrid appears once every year between 1960 and 2013. Do you have any idea how I could do this? I would also like to ensure that cities that have every year between 1960 and 1970 are also extended until 2013 with one observation per year.

    Do you have any idea how I could do this?

    Thank you in advance

    Enrique

  • #2
    Assuming that "city" is a string variable and there is at least one city that is observed in 1960 and in 2013:

    Code:
    encode city, gen(City)
    xtset City year
    tsfill, full
    drop city
    order City year
    As usual, the best way to get useful advice is to provide a data example using the dataex command (FAQ Advice #12).
    Last edited by Andrew Musau; 15 Jun 2023, 07:55.

    Comment

    Working...
    X