Announcement

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

  • Tag Change of Leader in a Dataset

    Dear all,

    I have a database with five columns:
    - country: the name of the country
    - year: the year
    - leader: the name of the leader in the country for the given year
    - ideology: the leader's ideology (left, right, centre)
    - party: corresponds to the political party of the leader

    For the different countries, I have information from 1945 to 2020 (sometimes less if the country is more recent).
    I would like to create three ‘tag’ variables:
    - a variable that is 1 when there is a change of leader at the head of the government,
    - a variable that is 1 when there is a change of ideology at the head of the government,
    - a variable that is 1 when there is a change of party at the head of the government.

    Could you help me?
    Thank you!

  • #2
    Assuming that you have at most one observation for each combination of country and year (i.e. country and year uniquely identify observations in the data set):

    Code:
    sort country year
    foreach v of varlist leader ideology party {
        by country (year): gen byte `v'_change = (`v' != `v'[_n-1])
    }

    Comment


    • #3
      Thanks a lot !
      It works perfectly !

      Comment


      • #4
        See also my paper on spells in the Stata Journal for 2007 and tsspell from SSC.

        Comment


        • #5
          Dear Clyde Schechter , Nick Cox ,

          Could you give me a hand, please?

          I'm analysing the effects of Fiscal consolidation episodes on FDI inflows. But I face a technical problem when I use lagged variable. Following my code:

          ppmlhdfe in_Flow_per_r L2.Fisc_r log_GDP_r log_POP_r res_rents_r remit_gdp_r access_elec_r gov_eff_r gdp_growth_r fin_dev_r elec_consump_r , vce(cl iso_r iso_p) absorb(iso_p#iso_r iso_p#year) nolog d keepsingletons separation(none)


          return: ppmlhdfe in_Flow_per_r L2.Fisc_r log_GDP_r log_POP_r res_rents_r remit_gdp_r access_elec_r gov_eff_r gdp_growth_r fin_dev_r elec_consump_r , vce(cl iso_r iso_p) absorb(iso_p#iso_r iso_p#year) nolog d keepsingletons separation(none)
          not sorted

          But I already did this:
          egen ID=group(iso_r iso_p)
          xtset ID year

          sort iso_p iso_r year

          Comment


          • #6
            Except for being addressed to different people, this post is an exact duplicate of https://www.statalist.org/forums/for...-using-reghdfe. It has no relevance to the topic of this thread at all, and is, at best, tangentially relevant in the other thread. These threads are not simply a dialog between a questioner and a responder. The Forum is a community of Stata users, and these threads are searched by titles and keywords and read by other users who encounter similar difficulties in the future. Digressing from the topic of a thread wastes the time of both those who search on the topic and then have to read something that is, to them, pointless, and those who are searching for the topic of your post, but cannot find it because it is not found in a search based on a relevant title or keyword. Also, those who would otherwise want to help you with this question may fail to do so because they aren't following these particular threads and would have no reason to expect to find this question buried here. So you are sabotaging your own search for help!

            In addition, it is usually not a good idea to address your posts to specific people, unless you are responding to something they said earlier in the thread and you want to make that context clear. By addressing your post to specific people you discourage the others in the Forum who might otherwise help you from even reading your post. You are better served by getting your answer from whichever Forum member attends to it first. Also, as in this case, at least with respect to me, your expectations about who would best help you may be wrong: I don't use -ppmlhdfe- myself and know nothing of its inner workings. (I have nothing against it, it's just that that particular model does not arise in my line of work.)

            I think your best chance of finding help with this problem is to repost this question in a new thread (click the New Topic button to start a new thread). Don't address your question to any particular person(s). In addition to showing the code you used (as you have done here), also show example data that reproduces the same error. Use the -dataex- command to show that example data so that whoever tries to help you can use it in Stata to troubleshoot the problem. If you are running version 16 or later, or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.
            Last edited by Clyde Schechter; 08 Jul 2025, 16:56.

            Comment


            • #7
              Sorry about that! This is my first time using the forum, and I wasn’t sure how to post properly. I really appreciate your advice and comments, and I’ll make sure to keep them in mind moving forward.

              Comment


              • #8
                As I too was pinged in #5 I looked at it but I have the same reaction as Clyde Schechter in #6. Posting a question in a thread with a completely different title can’t be a good principle, Pinging me on a topic in which I am no kind of expert in practice can’t help anybody. But please don’t feel a need to apologise again.

                Comment

                Working...
                X