Hello, I have a mock data set and one variable is "country" with the corresponding two letters "AT" for the few observations in my mock data set. (HFCS dataset)
Now the actual data is stored at the university (security reasons) so I have to write the code and then let it run through the data there, when I am done.
I am having trouble though with the before mentioned country variable though. Even though it appears in the data set as letters (AT) it seems to be encoded as either numeric or something else.
if I type keep if country == "AT" I get a mismatch error. The variable is type long and the format is %8.0g (whatever that means).
So I tried to change it via tostring and typed in the command
tostring country , generate(count)
But now the new variable doesn't have AT anymore, instead it has the number 1 for each entry. Although if I now put in the command
keep if count == "1" (doesn't work without the "", so it seems to be coded as non numeric) it at least performs the command and seems to yield no errors.
I was just wondering, is there a way to change the country variable in such a way, that I do keep the two letters and not change that into a number? Otherwise it will get very confusing once I have access to the entire data set and now have over 20 different countries.
Related Posts with Problem with variable and its format.
Add prefix on every Nth column in row X in panel data. Then, make row X the new variable names.I have a dataset containing stock data, looking like this: Code: * Example generated by -dataex-.…
How to check Study Size (count of participants included in meta-analysis) when conducting meta-analysis?Hello I am conducting meta-analysis on Stata 16 using meta set and meta summarize commands. The out…
Replacing missing values with previous non-missing values [Panel data]Hi everyone, I have 2-year panel data for households and it's members. I have a variable ramadan09 …
Setting the level() for lincomest, decimals don't workHi, I am trying to set a specific level for lincomest, but it only accepts numbers without decimals…
Extracting labels and renaming variables using loopsDear Statalist members, I am working with a dataset in .csv format that is separated in different f…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with variable and its format.
Post a Comment