Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Labeling values of variables


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Labeling values of variables
Date   Thu, 14 Feb 2008 15:46:57 -0000

One answer is to form a composite by 

egen group = group(relation sex), label 

and then form your own dummies using -tabulate, gen()-. 
But that still leaves rather ugly looking variable labels. 
You could in turn fix those with -labvarch- from -labutil- from SSC. 

That is all getting rather complicated. Here is a quick hack to 
do it in one. Note that 

nicelylabelleddummies varname, gen(frog) 

will produce the dummies for varname 

while 

nicelylabelleddummies var1 var2, gen(toad) 

will produce the dummies for var1*var2, but it won't produce 
produce dummies for var1 and var2 separately. 

*! NJC 1.0.0 14 Feb 2008 
program nicelylabelleddummies
	version 8.2 
	syntax varlist [if] [in], Generate(str) 
	marksample touse, strok 
	qui count if `touse' 
	if r(N) == 0 error 2000

	tempvar group 
	qui egen `group' = group(`varlist') if `touse', label 
	su `group', meanonly 
	local nvars = r(max) 
	forval i = 1/`nvars' { 
		capture confirm new variable `generate'`i' 
		if _rc { 
			di "`generate'`i' not acceptable as new varname"

			exit _rc 
		}
	} 

	qui tab `group' if `touse', gen(`generate') 

	forval i = 1/`nvars' { 
		local label : var label `generate'`i' 
		local label : subinstr local label "`group'==" "" 
		label var `generate'`i' `"`label'"' 
	} 
end 
	



Peter Dijkstra
==============

I like to have sensible value labels of variables, and use
   label define relation 0 "single" 1 "married" 2 "divorced"
   label define sex 0 "female" 1 "male"
in StataSE 8.2. However, when using
   xi i.relation * i.sex
the labels automatically become "relation==1 & sex==1", "relation==2 &
sex==1". How do I obtain labels which say "married male" and "divorced
male"?


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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