Announcement

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

  • Extending the last recorded value of a variable over several years

    Hi everyone,

    I have a panel dataset with a number of countries and time period between 1999-2020. I also have a variable "Fractionalization index" that starts from 1999 and stops at 2013. However, I want to extend its last recorded value till 2020 for each country. How can I do that on Stata?

    Many thanks,
    Yasmine

  • #2
    If you are using the original fractionalization indices by Alesina et al. (2003), then these are time-invariant and you can take the value at any one year, e.g.,

    Code:
    bys country (ethnic_fractionalization): replace ethnic_fractionalization= ethnic_fractionalization[1]
    Otherwise,

    Code:
    bys country (year): replace ethnic_fractionalization= ethnic_fractionalization[_n-1] if missing(ethnic_fractionalization) & !missing(ethnic_fractionalization[_n-1])

    Reference:
    Alesina, Alberto, Arnaud Devleeschauwer, William Easterly, Sergio Kurlat, and Romain Wacziarg. 2003. “Fractionalization.” Journal of Economic Growth 8 (2): 155–94.

    Comment


    • #3
      Hi Andrew,

      Thank you for replying! I'm using the Historical Index of Ethnic Fractionalization found here ( https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/4JQRCL ). When I tried to use the codes your provided it gave me an error "r(101)" and says that "Weights are not allowed". Any idea why that might be?

      Many thanks,
      Yasmine

      Comment


      • #4
        Provide a data example, e.g.,

        Code:
        dataex country year ethnic_fractionalization if year>=2010, count(30)

        Comment


        • #5
          Here you go!

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str30 Country int Year float efindex
          "Afghanistan" 2010 .757
          "Afghanistan" 2011 .759
          "Afghanistan" 2012 .761
          "Afghanistan" 2013 .763
          "Afghanistan" 2014    .
          "Afghanistan" 2015    .
          "Afghanistan" 2016    .
          "Afghanistan" 2017    .
          "Afghanistan" 2018    .
          "Afghanistan" 2019    .
          "Afghanistan" 2020    .
          "Albania"     2010 .133
          "Albania"     2011 .135
          "Albania"     2012 .137
          "Albania"     2013 .139
          "Albania"     2014    .
          "Albania"     2015    .
          "Albania"     2016    .
          "Albania"     2017    .
          "Albania"     2018    .
          "Albania"     2019    .
          "Albania"     2020    .
          "Algeria"     2010 .368
          "Algeria"     2011  .37
          "Algeria"     2012 .371
          "Algeria"     2013 .372
          "Algeria"     2014    .
          "Algeria"     2015    .
          "Algeria"     2016    .
          "Algeria"     2017    .
          end

          Comment


          • #6
            When I took Andrew Musau's solution in #2 and substitute your variable names for the ones used there, it runs completely fine without any error messages and produces the results you want.

            I suspect that in implementing his code you mistakenly inserted a blank space between efindex and [_n-1]. That produces exactly the error message you got. In some circumstances, when the Stata parser encounters [whatever] immediately preceded by a blank space, it thinks you are specifying weights to be applied, which, of course, is not legal syntax with -replace-. Subscript brackets should always be placed immediately adjacent to the variable being subscripted.

            Comment


            • #7
              Hi Clyde,

              You're absolutely right, that was the problem. Thank you very much! Andrew's code works just fine now.

              Comment

              Working...
              X