Announcement

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

  • Multiple observations and individuals in database for merge

    Hey everyone !

    I'm attempting to merge panel surveys database ( LSMS ). The problem I encounter is that in some database I have more than one observations per individual. exemple I'm studying the crop harvested per households and for each households I have more than one line ( see below ):

    Id Crop
    1 123
    1 124
    1 125
    2 127
    2 123
    3 209

    And in other base I have just one observation per household. What I would like to is redesign the database to have only one observation per household in attempt to merge all the database.
    I thought about creating dummie variables refering to the type of crop harvested, and to the others variable who have multiple observations but I can't imagine the time needed to do something like that for each database.
    I may be not really clear on my explanations but if you know a shorter way to do that let me know.

    Best regards

  • #2
    Sam:
    welcome to the list.
    I would start merging from the multiple lines database:
    Code:
    input Id Crop
    1 123
     1 124
     1 125
     2 127
     2 123
     3 209
    end
    save "C:\Users\user\Desktop\Sam_1.dta"
    drop _all
    set obs 3
    g Id=_n
    g Nation=_n
    label define Nation 1 "Argentina" 2 "Australia" 3 "Brazil"
    label val Nation Nation
    save "C:\Users\user\Desktop\Sam_2.dta", replace
    use "C:\Users\user\Desktop\Sam_1.dta", clear
    merge m:1 Id using "C:\Users\user\Desktop\Sam_2.dta", keepusing(Nation)
    save "C:\Users\user\Desktop\Sam_1.dta", replace
    Then you can decide which observations to -keep- (or -drop-) according to your research goals.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thanks for your answer your code was helpful.

      Kind regards,
      Sam

      Comment

      Working...
      X