I am having problems in appending some datasets because some variables do not have the same format between different datasets. I tried to destring all possible variables and saved the datasets again in order to append them all afterwards. But I still had the problem once some variables could not destring because it has some observations in string in some datasets. So I did the other way around: tostring all variables in all datasets before appending them all. the problem persists: some variables are string in a dataset and float in others
1st try:
foreach i in AC {
foreach a in 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 {
foreach k in 01 02 03 04 05 06 07 08 09 10 11 12 {
use ${AIHRED}/RD`i'`a'`k'.dta, clear
destring*, replace
save ${AIHRED_t}/RD`i'`a'`k'_t.dta, replace
clear
}
}
}
foreach i in AC {
use ${AIHRED_t}/RD`i'9201_t.dta, clear
foreach k in 02 03 04 05 06 07 08 09 10 11 12 {
append using ${AIHRED_t}/RD`i'92`k'_t.dta
}
foreach a in 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 {
foreach k in 01 02 03 04 05 06 07 08 09 10 11 12 {
append using ${AIHRED_t}/RD`i'`a'`k'_t.dta
}
}
destring *, replace
compress
save ${AIHRED_t}/RD`i'.dta, replace
clear
}
2nd try:
foreach i in AC {
foreach a in 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 {
foreach k in 01 02 03 04 05 06 07 08 09 10 11 12 {
use ${AIHRED}/RD`i'`a'`k'.dta, clear
tostring*, replace
save ${AIHRED_t}/RD`i'`a'`k'_t.dta, replace
clear
}
}
}
foreach i in AC {
use ${AIHRED_t}/RD`i'9201_t.dta, clear
foreach k in 02 03 04 05 06 07 08 09 10 11 12 {
append using ${AIHRED_t}/RD`i'92`k'_t.dta
}
foreach a in 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 {
foreach k in 01 02 03 04 05 06 07 08 09 10 11 12 {
append using ${AIHRED_t}/RD`i'`a'`k'_t.dta
}
}
destring *, replace
compress
save ${AIHRED_t}/RD`i'.dta, replace
clear
}
error displayed for the 2nd try:
variable us_sangue is str1 in master but float in using data
You could specify append's force option to ignore this string/numeric mismatch. The using variable would then be treated as if it
contained "".
r(106);
1st try:
foreach i in AC {
foreach a in 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 {
foreach k in 01 02 03 04 05 06 07 08 09 10 11 12 {
use ${AIHRED}/RD`i'`a'`k'.dta, clear
destring*, replace
save ${AIHRED_t}/RD`i'`a'`k'_t.dta, replace
clear
}
}
}
foreach i in AC {
use ${AIHRED_t}/RD`i'9201_t.dta, clear
foreach k in 02 03 04 05 06 07 08 09 10 11 12 {
append using ${AIHRED_t}/RD`i'92`k'_t.dta
}
foreach a in 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 {
foreach k in 01 02 03 04 05 06 07 08 09 10 11 12 {
append using ${AIHRED_t}/RD`i'`a'`k'_t.dta
}
}
destring *, replace
compress
save ${AIHRED_t}/RD`i'.dta, replace
clear
}
2nd try:
foreach i in AC {
foreach a in 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 {
foreach k in 01 02 03 04 05 06 07 08 09 10 11 12 {
use ${AIHRED}/RD`i'`a'`k'.dta, clear
tostring*, replace
save ${AIHRED_t}/RD`i'`a'`k'_t.dta, replace
clear
}
}
}
foreach i in AC {
use ${AIHRED_t}/RD`i'9201_t.dta, clear
foreach k in 02 03 04 05 06 07 08 09 10 11 12 {
append using ${AIHRED_t}/RD`i'92`k'_t.dta
}
foreach a in 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 {
foreach k in 01 02 03 04 05 06 07 08 09 10 11 12 {
append using ${AIHRED_t}/RD`i'`a'`k'_t.dta
}
}
destring *, replace
compress
save ${AIHRED_t}/RD`i'.dta, replace
clear
}
error displayed for the 2nd try:
variable us_sangue is str1 in master but float in using data
You could specify append's force option to ignore this string/numeric mismatch. The using variable would then be treated as if it
contained "".
r(106);
Comment