Announcement

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

  • Loosing data on merge

    I am merging 2 data sets, in master data set, the variables are byte with no data, and in the using data set they are strings.
    When they are merged, the data for these 2 variables is is lost.
    I've tried this with and without the tostring and format with the same results.
    This data set is expanding so I want to avoid having to check and manually input the missing data.
    Thanks for any ideas.

    Code:
    Here is the data I want to preserve:
    use "PlacesLived_V3.dta"
    
    tab1 a_2_districtText1 a_2_VDC1
    
    -> tabulation of a_2_districtText1  
    
    a_2_distric |
         tText1 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
     Bhairahawa |          1       50.00       50.00
        Chitwan |          1       50.00      100.00
    ------------+-----------------------------------
          Total |          2      100.00
    
    -> tabulation of a_2_VDC1  
    
       a_2_VDC1 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
     Bhairahawa |          1       50.00       50.00
          Tadhi |          1       50.00      100.00
    ------------+-----------------------------------
          Total |          2      100.00
    
    
    This is the master data set:
    use "ExploreV5", clear
    tostring a_2_districtText1 a_2_VDC1, replace force 
    format a_2_districtText1 a_2_VDC1 %11s
    
    a_2_districtText1 was byte now str1
    a_2_VDC1 was byte now str1
    
    
    merge 1:1 id using PlacesLived_V3, force
    (note: variable a_2_districtText1 was str1, now str10 to accommodate using data's values)
    (note: variable a_2_VDC1 was str1, now str10 to accommodate using data's values)
    
    tab1 a_2_districtText1 a_2_VDC1
    
    -> tabulation of a_2_districtText1  
    no observations
    
    -> tabulation of a_2_VDC1  
    no observations

  • #2
    Use dataex to show us what is going on. tostring will not look at value labels, although something else seems to be happening too.

    Comment


    • #3
      Using merge with the option update, fixed the problem.

      Comment

      Working...
      X