Announcement

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

  • Condense household observations

    Hi all,

    Apologies in advance, I'm an inexperienced undergrad.

    I have a dataset which has 1 household identifier variable, hhid, 2 profit variables (before an intervention, labeled profit_bl, and after an intervention, labeled profit_el) and 1 binary variable which indicates whether the observation was before or after the intervention, followup.

    Seeing as the values of profit_el and porfit_bl for each household member are the same, I want to reduce the observations in profit_bl and profit_el to 1 per household so that the baseline and endline profit values belong to the same observation. Previous threads have suggested using tag() with hhid but it seems a little more complex than that.

    Here is a screenshot of the data in the 'browse' tab:

    Click image for larger version

Name:	STATA query.png
Views:	1
Size:	19.8 KB
ID:	1705838


    Thanks very much in advance!

    Dan

  • #2
    Code:
    collapse (firstnm) profit_*, by(hhid)
    In the future, when showing data examples, please use the -dataex- command to do so. 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.

    Comment

    Working...
    X