Dear Statalisters,
I've imported a large .txt file to Stata using import delimited. The file has a few numeric variables, which are very long (18 digits) so Stata display them as e+ (e.g. 1.23e+17). I wanted these values to display in full so converted them to string, using
tostring(var), gen(newvar) format ("%20.0f")
However, some of the values returned inaccurate. So for instance, the correct value I expected (i.e. what is in the original .txt file) should have been 123456, but in Stata the it becomes 123457. It seems that after being converted they were rounded up somehow. What confuses me is that there's no decimal places, so it shouldn't be rounded up or down.
Could anyone shed any light on what might have happened and how do I fix this issue (i.e. to convert the numeric variables to string but keep the values the same as what they were in the original .txt file)?
Many thanks
Related Posts with tostring does not return correct values
Encoding CommandI am using encode to convert string variables into numeric, e.g. "NA" might get encoded to 0 or leav…
Convert Integer Date to Date FormatHi all, I have a problem with converting an integer-type date (format %d) to long-type date (%10.0g)…
Indicator VariableI would like to run a difference in difference regression to assess the early impact of country-by-c…
Mediation Analysis with multiple control variables and bootstrap CIsDear Statalist, after intensive studying of the available resources online, I am still left with so…
Propensity Score MatchingHi All I have two sets of data with values 0 and 1. The number of observations for dataset of value…
Subscribe to:
Post Comments (Atom)
0 Response to tostring does not return correct values
Post a Comment