Announcement

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

  • Merging Two datasets

    Dear All,

    I hope you are doing well. I have some additional district characteristics (e.g. No_Shrines_all_distr) in a using dataset which I want to add to the master dataset.

    My master dataset is as follows (where bench is my district identifier that is common in both datasets) :

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 bench float(No_Shrines_all_distr total_pop_distr) byte StateWins float caselag
    " banhc" . . 1 6
    " banhc" . . 1 6
    " banhc" . . 0 7
    " banhc" . . 0 3
    " khyhc" . . 1 5
    " khyhc" . . 1 4
    " khyhc" . . 1 2
    end


    My using dataset is as follows:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str5 bench byte No_Shrines_all_distr long total_pop_distr byte gov_archives
    "abohc" 0 880666 1
    "dikhc" 1  38990 1
    "kashc" 4  19593 1
    "phc"   1  53841 1
    "quehc" 0  84000 1
    "islhc" 0  77000 1
    "khyhc" 0 546730 1
    "sibhc" 1 180398 1
    end
    Now I want my No_Shrines_all_distr total_pop_distr to be filled with information from using dataset i.e. for my "using" dataset I know that the district "khyhc" has No_Shrines_all_distr to be 0, so I would want 0 in front the No_Shrines_all_distr every time an observation for khyhc appears in my master dataset, so far it is missing.

    Doing a many to 1 merge only helps me merge the new gov_archives variable but not the variables that exists in both data sets i.e. No_Shrines_all_distr long total_pop_distr
    Code:
    merge m:1 bench using ".\Gov_Shrines.dta"
    I also tried joinby but sort of got the same problem. Probably, I am not applying it correctly.

    Any help here to resolve this merging problem will be really appreciated.

    Cheers,

    Roger
    Last edited by Roger More; 14 Oct 2018, 14:16.

  • #2
    See the help file for -merge-. Perhaps the -update- option is what you are looking for.
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Thank you very much!

      Comment

      Working...
      X