Announcement

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

  • Copying Observations from Row

    My data looks somewhat like this:
    Exporter Importer Pairid Year Trade Value (USD) Distance CLanguage Contiguity RTA
    United States Canada 1 2018 25614.23 25468 1 1 1
    United States Canada 1 2019 546589.45 25468 1 1 1
    United States Canada 1 2020 546589.54
    United States Canada 1 2021 654585.28
    India China 2 2019 213131.58 24569 0 1 1
    India China 2 2020 121565.25
    India China 2 2021 565454.65
    (I just need to copy the missing values in rows for years 2020 and 2021 from year 2019 individually for each country pair with different Pairid)

    I have missing values for a few variables like (Distance, Contiguity, RTA) for all country pairs like United States and Canada with Pairid 1 for year 2020 and 2021. Keeping the new value of trade for years 2020 and 2021, I just want to copy the values of other variables from year 2019 to 2020 and 2021. I have a large number of Country Pairs like this with new trade data but no data on other variables. I just want to copy the observations for each country pair in 2019 and paste it for years 2020 and 2021 without copying or pasting the pairid or trade value.

  • #2
    Something like
    Code:
    bysort Pairid (Year):  replace Distance = Distance[_n-1] if missing(Distance)
    for each of the variables that you need to carry forward.

    Comment

    Working...
    X