Dear Statalisters:
I am trying to merge a country-level dataset and an individual-level dataset, as below. test1 has a country-level variable "GDP." test3 has individual-level variables "wage" and "productivity." GDP is a country-level variable, so the same value should appear for each country-year cell. But as you can see, GDP is missing after its first appearance in year. How can I make Stata repeat the same value of GDP for each country-year cell? ("indid" is individual id.)
Thank you in advance for your help.
Best wishes,
Taka
I am trying to merge a country-level dataset and an individual-level dataset, as below. test1 has a country-level variable "GDP." test3 has individual-level variables "wage" and "productivity." GDP is a country-level variable, so the same value should appear for each country-year cell. But as you can see, GDP is missing after its first appearance in year. How can I make Stata repeat the same value of GDP for each country-year cell? ("indid" is individual id.)
Thank you in advance for your help.
Best wishes,
Taka
Code:
. insheet using test1.csv
(4 vars, 11 obs)
. l
country year indid gdp
1. 1 1960 1 1
2. 2 1961 2 8
3. 3 1962 1 4
4. 4 1963 1 7
5. 5 1964 1 9
6. 6 1965 1 3
7. 7 1966 1 4
8. 8 1967 1 7
9. 9 1968 1 3
10. 10 1969 1 9
11. 11 1970 1 6
Code:
. insheet using test3.csv
(5 vars, 27 obs)
. l
country year indid wage produc~y
1. 1 1960 1 123 24
2. 1 1960 2 134 4
3. 1 1960 3 255 5
4. 1 1960 4 222 2
5. 1 1960 5 88 6
6. 1 1960 6 999 7
7. 1 1960 7 198 3
8. 1 1960 8 33 1
9. 1 1960 9 47 4
10. 1 1960 10 56 5
11. 1 1960 11 79 7
12. 2 1960 1 9 29
13. 3 1960 1 15 19
14. 4 1960 1 71 38
15. 5 1960 1 8 45
16. 5 1960 2 21 65
17. 5 1960 3 4 34
18. 5 1960 4 3 63
19. 5 1960 5 76 41
20. 5 1960 6 54 79
21. 5 1960 7 43 41
22. 6 1960 1 89 54
23. 7 1960 1 8 27
24. 8 1960 1 67 87
25. 9 1960 1 10 13
26. 10 1960 1 15 15
27. 11 1960 1 13 67
Code:
. merge 1:1 country year indid using test3
Result Number of obs
Not matched 36
from master 10 (_merge==1)
from using 26 (_merge==2)
Matched 1 (_merge==3)
Code:
. sort country year indid
. l
country year indid gdp wage produc~y _merge
1. 1 1960 1 1 123 24 Matched (3)
2. 1 1960 2 . 134 4 Using only (2)
3. 1 1960 3 . 255 5 Using only (2)
4. 1 1960 4 . 222 2 Using only (2)
5. 1 1960 5 . 88 6 Using only (2)
6. 1 1960 6 . 999 7 Using only (2)
7. 1 1960 7 . 198 3 Using only (2)
8. 1 1960 8 . 33 1 Using only (2)
9. 1 1960 9 . 47 4 Using only (2)
10. 1 1960 10 . 56 5 Using only (2)
11. 1 1960 11 . 79 7 Using only (2)
12. 2 1960 1 . 9 29 Using only (2)
13. 2 1961 2 8 . . Master only (1)
14. 3 1960 1 . 15 19 Using only (2)
15. 3 1962 1 4 . . Master only (1)
16. 4 1960 1 . 71 38 Using only (2)
17. 4 1963 1 7 . . Master only (1)
18. 5 1960 1 . 8 45 Using only (2)
19. 5 1960 2 . 21 65 Using only (2)
20. 5 1960 3 . 4 34 Using only (2)
21. 5 1960 4 . 3 63 Using only (2)
22. 5 1960 5 . 76 41 Using only (2)
23. 5 1960 6 . 54 79 Using only (2)
24. 5 1960 7 . 43 41 Using only (2)
25. 5 1964 1 9 . . Master only (1)
26. 6 1960 1 . 89 54 Using only (2)
27. 6 1965 1 3 . . Master only (1)
28. 7 1960 1 . 8 27 Using only (2)
29. 7 1966 1 4 . . Master only (1)
30. 8 1960 1 . 67 87 Using only (2)
31. 8 1967 1 7 . . Master only (1)
32. 9 1960 1 . 10 13 Using only (2)
33. 9 1968 1 3 . . Master only (1)
34. 10 1960 1 . 15 15 Using only (2)
35. 10 1969 1 9 . . Master only (1)
36. 11 1960 1 . 13 67 Using only (2)
37. 11 1970 1 6 . . Master only (1)

Comment