Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Import value labels from text file


From   Sven-Oliver Spieß <svenoliverspiess@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Import value labels from text file
Date   Sat, 12 Dec 2009 01:32:18 +0100

Hi Jorge,

Yes. Assuming you have two textfiles origin and sex as follows:

	---Beginning origin.txt---
	0 `"Domestic"'
	1 `"Foreign"'
	---End origin.txt---

	---Beginning sex.txt---
	1 `"Female"'
	2 `"Male"'
	---End sex.txt---

You could create the value labels e.g. like that:

	--- Beginning example.do---
	version 11.0

	file open first using origin.txt, r t
	file read first line
	while r(eof)==0 {
		label define origin `line', modify
		file read first line
		}	
	file close first

	file open second using sex.txt, r t
	file read second line
	while r(eof)==0 {
		label define sex `line', modify
		file read second line
		}	
	file close second

	label list
	exit
	---End example.do---


You can find more detailed information via "help file" and in particular
"help file##2.2".

Also as long as your labels don't contain blanks it doesn't matter if
they are in quotes or not. Otherwise you'll have to find a work-around.


Cheers,
Sven-Oliver
	

On Fri, 2009-12-11 at 18:27 -0500, Jorge Eduardo Pérez Pérez wrote:
> Dear Statalist:
> 
> I have many textfiles that contain value label information, in the
> following format:
> 
> 1 labelfor1
> 2 labelfor2
> ...
> 
> Is it possible to import this information to Stata and assign it to
> variables in a dataset? I've had bad luck searching ...
> 
> Thank you
> 
> _______________________
> Jorge Eduardo Pérez Pérez
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index