Announcement

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

  • Taking difference of variables by grouping with respect to another variable

    Hi all,

    I have a big dataset consisting of cities, years, and economic variables with respect to those variables. I want to take the differences in unemployment rates of cities between two years (let's say 2011 and 2015). How can I define a variable so that:

    gen difference_11_15_unemployment =

    gives the unemployment rate differences between the years 2011 and 2015. Note that my data consist of 20 years, so the variable value of "difference_11_15_unemployment" will be the same for a given city for all observations.

    Thank you for your time.





  • #2
    Please read the Forum FAQ for excellent advice on how to pose questions in ways that maximize the chance of getting a timely and helpful response. In particular, when asking for help with code, you should provide example data. This is critical because nobody can guess how your data are organized within the data set, and without that information it is impossible to know which approach to use. Moreover, please pay particular attention to FAQ #12 where you will learn about the -dataex- command which provides the best, most helpful, way to show example data. If you are running version 17, 16 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.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Please post back with example data. If you do that, you will likely get a timely and helpful response.

    Comment

    Working...
    X