Dear Statalist,
I am currently using the -import command- to get .txt files into .dta files.
Even tough I want in fact to read the first observations in the .txt files as variable names in Stata, the existence of repeated variables and variables with equal names in the .txt file prevents-me to load the data to Stata. The solution is therefore to do not take first observations as variable names and to, set the option [, varnames(1)] instead of [, varnames(nonames)].
But then first observations contain blank spaces which do not allow me for an easy replacement as variable names that, by definition, can have no spaces.
So, in my view I first have to eliminate blank spaces so that I can run a -foreach- program to rename variable with the contents of the first observation. But I don't know how I should proceed with this since the more usual character replacement works by variable and not by observation (for instance: replace var1=subinstr(var1,"`=char(xx)'","",.).
I have also looked at how could I apply -forvalues- ( http://www.stata.com/statalist/archi.../msg01171.html ) and -foreach- ( http://www.stata.com/statalist/archi.../msg00825.html )
examples as well as a renvars ( http://www.stata.com/statalist/archi.../msg01177.html ) but I am also not sure how to adapt these programs.
Any help on this would be greatly appreciated,
André Coelho
I am currently using the -import command- to get .txt files into .dta files.
Even tough I want in fact to read the first observations in the .txt files as variable names in Stata, the existence of repeated variables and variables with equal names in the .txt file prevents-me to load the data to Stata. The solution is therefore to do not take first observations as variable names and to, set the option [, varnames(1)] instead of [, varnames(nonames)].
But then first observations contain blank spaces which do not allow me for an easy replacement as variable names that, by definition, can have no spaces.
So, in my view I first have to eliminate blank spaces so that I can run a -foreach- program to rename variable with the contents of the first observation. But I don't know how I should proceed with this since the more usual character replacement works by variable and not by observation (for instance: replace var1=subinstr(var1,"`=char(xx)'","",.).
I have also looked at how could I apply -forvalues- ( http://www.stata.com/statalist/archi.../msg01171.html ) and -foreach- ( http://www.stata.com/statalist/archi.../msg00825.html )
examples as well as a renvars ( http://www.stata.com/statalist/archi.../msg01177.html ) but I am also not sure how to adapt these programs.
Any help on this would be greatly appreciated,
André Coelho
Comment