Dear forum,
With regards to my csv import issue, I am stuck with several datasets which need manual adjustment of variable values, due to incorrect import of the data. See https://www.statalist.org/forums/for...imiter-symbols, for my import issue.
My general idea was to split one of my datasets in several parts, precisely one part which contains all data which is fine and other parts which need manual adjustment. After, I merge them back together.
Suppose the original data has the variables, a - e, the imported that has variables a - e and v6, with a - e being random variable names. I split the data whether or not the observations have a missing value for v6 to determine, correctly and not correctly imported data.
For the incorrect imported data, variable a should actually be a+b, b be c and so on.
What I did was,
which worked for me. However, I am looking for a more general solution if there is any as I am always renaming the variable with the variable name of the previous variable. Besides, renaming around 20 to 30 variables, most of them with long variable names looks pretty messy in my opinion.
Does anybody know a way of dealing with this issue more smoothly?
Alternatively, I tried:
This does only work if all my variables are string variables, which is not always the case. If, however this is the case, is there a way to loop this? I was thinking of something like,
but do not know how to specify that he should replace `var' with `var' +1.
Thank you very much in advance.
Best regards,
Ali
With regards to my csv import issue, I am stuck with several datasets which need manual adjustment of variable values, due to incorrect import of the data. See https://www.statalist.org/forums/for...imiter-symbols, for my import issue.
My general idea was to split one of my datasets in several parts, precisely one part which contains all data which is fine and other parts which need manual adjustment. After, I merge them back together.
Suppose the original data has the variables, a - e, the imported that has variables a - e and v6, with a - e being random variable names. I split the data whether or not the observations have a missing value for v6 to determine, correctly and not correctly imported data.
For the incorrect imported data, variable a should actually be a+b, b be c and so on.
What I did was,
Code:
replace a = a + ";" + b drop b rename (c d e v6) (b c d e)
Does anybody know a way of dealing with this issue more smoothly?
Alternatively, I tried:
Code:
replace a = a + ";" + b replace b = c ... replace e = v6 drop v6
Code:
foreach var of varlist b c d e v6{ replace `var' = ... }
Thank you very much in advance.
Best regards,
Ali
Comment