Dear Statalist Users,
I am trying to merge 2 datasets but before that I am aggregating my data at GADM1 level (which is NAME_1 variable in the dataset). To that extent, I have created the following variables.
gen sub2=sub
gen NAME_1=.
gen NAME_0=ctr_n
Then, for example, for Angola, I was trying to replace my NAME_1 variable but I am receiving "type mismatch" error when I run the below mentioned code.
* ANGOLA
replace NAME_1="Bengo" if NAME_0=="Angola" & sub2=="Bengo"
replace NAME_1="Cunene" if NAME_0=="Angola" & sub2=="Cunene"
replace NAME_1="Luanda" if NAME_0=="Angola" & sub2=="Luanda"
replace NAME_1="Moxico" if NAME_0=="Angola" & sub2=="Moxico"
NAME_1 and NAME_0 variables are super important because I will use them as identifiers while merging and I will also use them as Fixed Effects in my regression. How can I solve that problem?
Thank you so much
Here is an example of my data:
I am trying to merge 2 datasets but before that I am aggregating my data at GADM1 level (which is NAME_1 variable in the dataset). To that extent, I have created the following variables.
gen sub2=sub
gen NAME_1=.
gen NAME_0=ctr_n
Then, for example, for Angola, I was trying to replace my NAME_1 variable but I am receiving "type mismatch" error when I run the below mentioned code.
* ANGOLA
replace NAME_1="Bengo" if NAME_0=="Angola" & sub2=="Bengo"
replace NAME_1="Cunene" if NAME_0=="Angola" & sub2=="Cunene"
replace NAME_1="Luanda" if NAME_0=="Angola" & sub2=="Luanda"
replace NAME_1="Moxico" if NAME_0=="Angola" & sub2=="Moxico"
NAME_1 and NAME_0 variables are super important because I will use them as identifiers while merging and I will also use them as Fixed Effects in my regression. How can I solve that problem?
Thank you so much
Here is an example of my data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str30 ctr_n str75 sub2 float NAME_1 str30 NAME_0 str75 sub "Cameroon" "north" . "Cameroon" "north" "Cameroon" "north" . "Cameroon" "north" "Cameroon" "north" . "Cameroon" "north" "Cameroon" "north" . "Cameroon" "north" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "northwest" . "Cameroon" "northwest" "Cameroon" "northwest" . "Cameroon" "northwest" "Cameroon" "northwest" . "Cameroon" "northwest" "Cameroon" "northwest" . "Cameroon" "northwest" "Cameroon" "northwest" . "Cameroon" "northwest" "Cameroon" "northwest" . "Cameroon" "northwest" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "south" . "Cameroon" "south" "Cameroon" "south" . "Cameroon" "south" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "northwest" . "Cameroon" "northwest" "Cameroon" "northwest" . "Cameroon" "northwest" "Cameroon" "northwest" . "Cameroon" "northwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "north" . "Cameroon" "north" "Cameroon" "north" . "Cameroon" "north" "Cameroon" "north" . "Cameroon" "north" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "center" . "Cameroon" "center" "Cameroon" "center" . "Cameroon" "center" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "west" . "Cameroon" "west" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "center" . "Cameroon" "center" "Cameroon" "center" . "Cameroon" "center" "Cameroon" "center" . "Cameroon" "center" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "east" . "Cameroon" "east" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "southwest" . "Cameroon" "southwest" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "adamowa" . "Cameroon" "adamowa" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" "Cameroon" "far north" . "Cameroon" "far north" end

Comment