Dear Stata users,
I have a database with import values of format %10.0g (double storage type). Since I have duplicate observations for some countries but with different values, I am first summing them
Then, I would like to keep the maximum value and keep only observations where values of imports and imports2 are matching.
However, the maximum value generated does not always match with the variable imports even if there is only one value.
For instance, the value for the variable imports for one observation could be 22224567 and the maximum value (imports2) is 22224568. So the figure is different only for the last figure even though I have changed the format of the maximum variable generated to match with the format of the initial variable.
And therefore the last line of my code eliminates many observations that should be kept.
Could you help me to fixe this ?
Many thanks.
I have a database with import values of format %10.0g (double storage type). Since I have duplicate observations for some countries but with different values, I am first summing them
Code:
bysort prod year importer : replace imports=sum(imports) if exporter == "DEU"
Code:
bysort year importer exporter prod : egen imports2 = max(imports) format imports2 %10.0g keep if(imports == imports2)
For instance, the value for the variable imports for one observation could be 22224567 and the maximum value (imports2) is 22224568. So the figure is different only for the last figure even though I have changed the format of the maximum variable generated to match with the format of the initial variable.
And therefore the last line of my code eliminates many observations that should be kept.
Could you help me to fixe this ?
Many thanks.
Comment