Dear Statalisters,
The process of my coding is:
I was expecting 4 observation after appending two datasets together, but I only got two.
What did I do wrong?
match1975_sic2834 (first data)
clear
input int(gvkey eyear) byte(prex postx)
1000 1975 3 4
1001 1975 2 3
end
match1975_sic3334
clear
input int(gvkey eyear) byte(prex postx)
1002 1975 3 4
1003 1975 2 3
end
master
clear
input int(gvkey eyear y)
1000 1975 11
1001 1975 232
1002 1975 32
1003 1975 56
1004 1976 2
end
question #2: above I presented 2 datasets match1975_sic2834 , match1975_sic3334. I have 88 other datasets such as match1976_sic2511, match1976_sic2512, you see the pattern of the name of my data, the year are changing (1975 1976 etc), and the 4 numbers after sic are changing. My task is to merge in all 90 data with the master, and do some computation, and save the data, and append all the saved ones together.
What is the succinct way of doing this ? I think i need modify my code above with two foreach loop, given that the numbers after sic changes from year to year,so I was not sure if I can use two foreach loop , loop 1 takes year, loop 2 take number after sic.
thank you,
Rochelle
The process of my coding is:
- I have 90 small datasets to be merged into a master data
- Let us say we start with first merge
- Compute some values after merging
- Save the data , repeat step 2 ,3,4 with the second dataset merge with master, append to last saved data.
I was expecting 4 observation after appending two datasets together, but I only got two.
What did I do wrong?
match1975_sic2834 (first data)
clear
input int(gvkey eyear) byte(prex postx)
1000 1975 3 4
1001 1975 2 3
end
match1975_sic3334
clear
input int(gvkey eyear) byte(prex postx)
1002 1975 3 4
1003 1975 2 3
end
master
clear
input int(gvkey eyear y)
1000 1975 11
1001 1975 232
1002 1975 32
1003 1975 56
1004 1976 2
end
Code:
foreach x of numlist 2834 3334 { clear save event`x'_prepost, replace emptyok quie { use match1975_sic`x',clear merge using master keep if _merge==3 * I omitted the computation of variables here, it should not affect the append process drop _merge append using event`x'_prepost save event`x'_prepost, replace } }
question #2: above I presented 2 datasets match1975_sic2834 , match1975_sic3334. I have 88 other datasets such as match1976_sic2511, match1976_sic2512, you see the pattern of the name of my data, the year are changing (1975 1976 etc), and the 4 numbers after sic are changing. My task is to merge in all 90 data with the master, and do some computation, and save the data, and append all the saved ones together.
What is the succinct way of doing this ? I think i need modify my code above with two foreach loop, given that the numbers after sic changes from year to year,so I was not sure if I can use two foreach loop , loop 1 takes year, loop 2 take number after sic.
thank you,
Rochelle
Comment