@alexandraqn I wanted to comment on the version you have created for MEX 2005 GLD that now incorporates the ISIC version after merging in the information from the NAICS-ISIC correspondance. I do it here because I can link to specific lines, which makes it visually clearer.
The first thing I wanted to point to is the repetition of the local path_in
. as you can see below, path_in
is defined in line 60 but then in line 70 and 72. This instances are not needed (if run all at a time - if you run a bit of the code from the do file, the next time you run something from there all previously created locals will have been wiped).
|
local path_in "C:\Users\wb582018\OneDrive - WBG\Surveys\MEX\MEX_2005_LFS\MEX_2005_LFS_v01_M\Data\Original" |
|
local path_output "C:\Users\wb582018\OneDrive - WBG\Surveys\MEX\MEX_2005_LFS\MEX_2005_LFS_v01_M_v01_A_GLD\Data\Harmonized" |
|
|
|
*----------1.3: Database assembly------------------------------* |
|
|
|
* All steps necessary to merge datasets (if several) to have all elements needed to produce |
|
* harmonized output in a single file |
|
use "`path_in'\VIVT105.dta",clear |
|
drop p1-p3 |
|
destring loc mun est ageb t_loc cd_a upm d_sem n_pro_viv ent con v_sel n_ent per, replace |
|
local path_in "C:\Users\wb582018\OneDrive - WBG\Surveys\MEX\MEX_2005_LFS\MEX_2005_LFS_v01_M\Data\Original" |
|
merge 1:m ent con v_sel using "`path_in'\HOGT105.dta", nogen |
|
local path_in "C:\Users\wb582018\OneDrive - WBG\Surveys\MEX\MEX_2005_LFS\MEX_2005_LFS_v01_M\Data\Original" |
|
merge 1:m ent con v_sel n_hog using "`path_in'\SDEMT105.dta" |
The second issue refers to the location of the file. As seen below lines 92 and 98 define where the the NAICS-ISIC file is read from. This should be ...\MEX_2005_ENOE\MEX_2005_ENOE_v01_M\Data\Stata
. Recall what we discussed yesterday, the INEGI excel file is to be under Doc
, the R
code that creates the .dta
file under Programs
and the output of the R
code under Data\Stata
. Furthermore, on the GLD-Harmonization
system, please ensure that Stata files are under Data\Stata
and not Data\Original
- I think you have done it for all but 2005.
|
*ISIC |
|
***first job |
|
gen scian_1=p4a |
|
tostring scian_1, replace |
|
merge m:1 scian_1 using "C:\Users\wb582018\OneDrive - WBG\Documents\Industry Classification\SCIAN_02_ISIC_3.1\SCIAN_02_ISIC_3.1.dta", keep(master match) |
|
rename scian_1 scian_11 |
|
drop _merge |
|
***second job |
|
gen scian_1=p7c |
|
tostring scian_1, replace |
|
merge m:1 scian_1 using "C:\Users\wb582018\OneDrive - WBG\Documents\Industry Classification\SCIAN_02_ISIC_3.1\SCIAN_02_ISIC_3.1.dta", keep(master match) |
|
rename scian_1 scian_2 |
|
drop _merge |
The third issue relates to the same place, in particular to lines 92 and 98 more in detail. The lines are:
|
merge m:1 scian_1 using "C:\Users\wb582018\OneDrive - WBG\Documents\Industry Classification\SCIAN_02_ISIC_3.1\SCIAN_02_ISIC_3.1.dta", keep(master match) |
|
merge m:1 scian_1 using "C:\Users\wb582018\OneDrive - WBG\Documents\Industry Classification\SCIAN_02_ISIC_3.1\SCIAN_02_ISIC_3.1.dta", keep(master match) |
Previously you have created scian_1
by doing first gen scian_1=p4a
and then tostring scian_1, replace
. You can, by the way, do this in one command as tostring p4a, gen(scian_1)
. So now you have on your master file variables scian
and scian_1
, while the NAICS-ISIC file contains variable scian
.
Your merge command merge m:1 scian_1 using "file path", keep(match master)
does not work for me. Have you changed the R
file so that SCIAN_02_ISIC_3.1.dta
has a variable scian_1
instead of scian
?
I propose the following, which did work for me:
*ISIC
***first job
rename scian scian_orig // get rid of the scian that was already there in the raw data
tostring p4a, gen(scian)
merge m:1 scian using "C:\Users\wb529026\OneDrive - WBG\Documents\Country Work\MEX\Industry Classification\SCIAN_02_ISIC_3.1.dta", keep(master match) nogen
rename scian scian_1
***second job
tostring p7c, gen(scian)
merge m:1 scian using "C:\Users\wb529026\OneDrive - WBG\Documents\Country Work\MEX\Industry Classification\SCIAN_02_ISIC_3.1.dta", keep(master match) nogen
rename scian scian_2
Note that my using "path file"
here in the merge commands is also incorrect as the SCIAN_02_ISIC_3.1.dta
file is not under Data\Stata
.
While I am here, a final point on variable abbreviation. The definition of male
is based on the original variable sexo
which in your code is just sex
. This works because Stata allows by default variable abbreviation.
|
*<_male_> |
|
gen male = sex |
|
recode male 2=0 |
|
label var male "Sex - Ind is male" |
|
la de lblmale 1 "Male" 0 "Female" |
|
label values male lblmale |
|
*</_male_> |
I think it is best to always reference the full variable. I can even imagine you wanted to type sexo
but it just happened because you were typing quickly and this goes unnoticed because Stata is - inadvertently - making assumptions about what it thinks you meant. You should be in full control of this process.
Let me know of any questions you may have and thanks a bunch for this!