Announcement

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

  • Generate variable capturing properties of other variables

    Dear all,

    I have a household survey dataset consisting of two rounds. The dataset provides information on the month and the year of the interview. In round 1, a household could have been interviewed either in 2004 or in 2005 in any month. In round two, a household could have been interviewed either in 2011 or in 2012 in any month.
    Additionally, I have monthly weather data for every year (e.g. T2004_1 for average temperature in January 2004).

    I would like to generate a variable that captures the following information for every household for every round: average spring (January-March), summer (June-September) and winter (October-November) temperature and precipitation preceding the interview.
    So for instance, for a household that was interviewed in round 1 in December 2004 the variables would be generated for the year 2004.

    However, a household that was interviewed in June 2004 would draw on both, information from 2003 on winter and summer weather and 2004 for spring weather. I am however not really sure how to generate this variable. Could anyone please help?

    Many thanks.


  • #2
    The details of the code will depend on the exact organization and encoding of your data. I don't think anyone can give you a useful response without seeing example data. Please post back, using the -dataex- command to show example data.

    In the future, when showing data examples, please use the -dataex- command to do so. If you are running
    version 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-.

    Comment

    Working...
    X