Need some help guys,
. dataex
----------------------- copy starting from the next line -----------------------
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input str8 date str18 source str19 target str4 cameocode int numevents long numarts byte quadclass float goldstein str2 EventRootCode str19 target_cloned str3 target_country_only str6 MonthYear
"19790101" "BUS" "USA" "040" 1 4 1 1 "04" "USA" "USA" "197901"
"19790101" "CHN" "USA" "017" 1 2 1 0 "01" "USA" "USA" "197901"
"19790101" "CHN" "USA" "036" 5 16 1 4 "03" "USA" "USA" "197901"
"19790101" "CHN" "USA" "042" 3 9 1 1.9 "04" "USA" "USA" "197901"
"19790101" "CHN" "USA" "051" 2 2 1 3.4 "05" "USA" "USA" "197901"
"19790101" "COP" "USA" "190" 1 4 4 -10 "19" "USA" "USA" "197901"
"19790101" "CUBGOV" "USA" "017" 1 5 1 0 "01" "USA" "USA" "197901"
"19790101" "CUBGOV" "USA" "050" 1 5 1 3.5 "05" "USA" "USA" "197901"
"19790101" "CUBGOV" "USA" "111" 1 5 3 -2 "11" "USA" "USA" "197901"
"19790101" "CUB" "USA" "017" 1 4 1 0 "01" "USA" "USA" "197901"
"19790101" "CUB" "USA" "050" 1 4 1 3.5 "05" "USA" "USA" "197901"
"19790101" "CUB" "USA" "111" 1 4 3 -2 "11" "USA" "USA" "197901"
"19790101" "EDU" "USA" "040" 1 5 1 1 "04" "USA" "USA" "197901"
"19790101" "EDU" "USA" "182" 1 5 4 -9.5 "18" "USA" "USA" "197901"
"19790101" "JUD" "USA" "020" 1 5 1 3 "02" "USA" "USA" "197901"
"19790101" "JUD" "USA" "051" 1 2 1 3.4 "05" "USA" "USA" "197901"
"19790101" "JUD" "USA" "120" 1 7 3 -4 "12" "USA" "USA" "197901"
"19790101" "LEG" "USA" "042" 2 4 1 1.9 "04" "USA" "USA" "197901"
"19790101" "LEG" "USA" "120" 1 7 3 -4 "12" "USA" "USA" "197901"
"19790101" "MIL" "USA" "0334" 2 9 1 6 "03" "USA" "USA" "197901"
"19790101" "USAJUD" "USA" "046" 1 2 1 7 "04" "USA" "USA" "197901"
"19790101" "USAPRIJUD" "USA" "080" 1 4 2 5 "08" "USA" "USA" "197901"
"19790101" "UZB" "USA" "040" 1 1 1 1 "04" "USA" "USA" "197901"
"19790102" "BUS" "USA" "010" 1 2 1 0 "01" "USA" "USA" "197901"
"19790102" "BUS" "USA" "013" 1 5 1 .4 "01" "USA" "USA" "197901"
"19790102" "BUS" "USA" "050" 2 7 1 3.5 "05" "USA" "USA" "197901"
"19790102" "CHN" "USA" "036" 1 2 1 4 "03" "USA" "USA" "197901"
"19790102" "CHN" "USA" "051" 2 7 1 3.4 "05" "USA" "USA" "197901"
"19790102" "CHN" "USA" "110" 1 5 3 -2 "11" "USA" "USA" "197901"
"19790102" "COL" "USA" "036" 1 9 1 4 "03" "USA" "USA" "197901"
"19790102" "COL" "USA" "042" 4 18 1 1.9 "04" "USA" "USA" "197901"
"19790102" "COP" "USA" "036" 1 1 1 4 "03" "USA" "USA" "197901"
"19790102" "COP" "USA" "043" 1 2 1 2.8 "04" "USA" "USA" "197901"
"19790102" "COP" "USA" "190" 1 7 4 -10 "19" "USA" "USA" "197901"
"19790102" "CUBGOVMIL" "USA" "111" 1 5 3 -2 "11" "USA" "USA" "197901"
"19790102" "CUB" "USA" "043" 1 3 1 2.8 "04" "USA" "USA" "197901"
"19790102" "CUB" "USA" "111" 2 4 3 -2 "11" "USA" "USA" "197901"
"19790102" "CVLGOV" "USA" "036" 2 3 1 4 "03" "USA" "USA" "197901"
"19790102" "DEUCVL" "USA" "030" 1 2 1 4 "03" "USA" "USA" "197901"
above is an example of my data.
I want to get a count for all specific EventRootCodes in my data per month. therefore I thought creating new variables would do.
, would create erc1, merely taking the count of the amount of eventrootcode with code 01 per month. and I would do this for all eventrootcodes for example.
. egen ERC1=sum( EventRootCode==01),by(MonthYear)
type mismatch
r(109);
error.
- how to fix this. both variable are string thus I thought this would not be a problem.
- when trying to destring them to another data type I get:
. destring EventRootCode,replace
EventRootCode contains nonnumeric characters; no replace
what am I doing wrong here. thank you
. dataex
----------------------- copy starting from the next line -----------------------
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input str8 date str18 source str19 target str4 cameocode int numevents long numarts byte quadclass float goldstein str2 EventRootCode str19 target_cloned str3 target_country_only str6 MonthYear
"19790101" "BUS" "USA" "040" 1 4 1 1 "04" "USA" "USA" "197901"
"19790101" "CHN" "USA" "017" 1 2 1 0 "01" "USA" "USA" "197901"
"19790101" "CHN" "USA" "036" 5 16 1 4 "03" "USA" "USA" "197901"
"19790101" "CHN" "USA" "042" 3 9 1 1.9 "04" "USA" "USA" "197901"
"19790101" "CHN" "USA" "051" 2 2 1 3.4 "05" "USA" "USA" "197901"
"19790101" "COP" "USA" "190" 1 4 4 -10 "19" "USA" "USA" "197901"
"19790101" "CUBGOV" "USA" "017" 1 5 1 0 "01" "USA" "USA" "197901"
"19790101" "CUBGOV" "USA" "050" 1 5 1 3.5 "05" "USA" "USA" "197901"
"19790101" "CUBGOV" "USA" "111" 1 5 3 -2 "11" "USA" "USA" "197901"
"19790101" "CUB" "USA" "017" 1 4 1 0 "01" "USA" "USA" "197901"
"19790101" "CUB" "USA" "050" 1 4 1 3.5 "05" "USA" "USA" "197901"
"19790101" "CUB" "USA" "111" 1 4 3 -2 "11" "USA" "USA" "197901"
"19790101" "EDU" "USA" "040" 1 5 1 1 "04" "USA" "USA" "197901"
"19790101" "EDU" "USA" "182" 1 5 4 -9.5 "18" "USA" "USA" "197901"
"19790101" "JUD" "USA" "020" 1 5 1 3 "02" "USA" "USA" "197901"
"19790101" "JUD" "USA" "051" 1 2 1 3.4 "05" "USA" "USA" "197901"
"19790101" "JUD" "USA" "120" 1 7 3 -4 "12" "USA" "USA" "197901"
"19790101" "LEG" "USA" "042" 2 4 1 1.9 "04" "USA" "USA" "197901"
"19790101" "LEG" "USA" "120" 1 7 3 -4 "12" "USA" "USA" "197901"
"19790101" "MIL" "USA" "0334" 2 9 1 6 "03" "USA" "USA" "197901"
"19790101" "USAJUD" "USA" "046" 1 2 1 7 "04" "USA" "USA" "197901"
"19790101" "USAPRIJUD" "USA" "080" 1 4 2 5 "08" "USA" "USA" "197901"
"19790101" "UZB" "USA" "040" 1 1 1 1 "04" "USA" "USA" "197901"
"19790102" "BUS" "USA" "010" 1 2 1 0 "01" "USA" "USA" "197901"
"19790102" "BUS" "USA" "013" 1 5 1 .4 "01" "USA" "USA" "197901"
"19790102" "BUS" "USA" "050" 2 7 1 3.5 "05" "USA" "USA" "197901"
"19790102" "CHN" "USA" "036" 1 2 1 4 "03" "USA" "USA" "197901"
"19790102" "CHN" "USA" "051" 2 7 1 3.4 "05" "USA" "USA" "197901"
"19790102" "CHN" "USA" "110" 1 5 3 -2 "11" "USA" "USA" "197901"
"19790102" "COL" "USA" "036" 1 9 1 4 "03" "USA" "USA" "197901"
"19790102" "COL" "USA" "042" 4 18 1 1.9 "04" "USA" "USA" "197901"
"19790102" "COP" "USA" "036" 1 1 1 4 "03" "USA" "USA" "197901"
"19790102" "COP" "USA" "043" 1 2 1 2.8 "04" "USA" "USA" "197901"
"19790102" "COP" "USA" "190" 1 7 4 -10 "19" "USA" "USA" "197901"
"19790102" "CUBGOVMIL" "USA" "111" 1 5 3 -2 "11" "USA" "USA" "197901"
"19790102" "CUB" "USA" "043" 1 3 1 2.8 "04" "USA" "USA" "197901"
"19790102" "CUB" "USA" "111" 2 4 3 -2 "11" "USA" "USA" "197901"
"19790102" "CVLGOV" "USA" "036" 2 3 1 4 "03" "USA" "USA" "197901"
"19790102" "DEUCVL" "USA" "030" 1 2 1 4 "03" "USA" "USA" "197901"
above is an example of my data.
I want to get a count for all specific EventRootCodes in my data per month. therefore I thought creating new variables would do.
egen ERC1=sum( EventRootCode==01),by(MonthYear)
. egen ERC1=sum( EventRootCode==01),by(MonthYear)
type mismatch
r(109);
error.
- how to fix this. both variable are string thus I thought this would not be a problem.
- when trying to destring them to another data type I get:
. destring EventRootCode,replace
EventRootCode contains nonnumeric characters; no replace
what am I doing wrong here. thank you
Comment