Statalist


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

Re: st: RE: Labeling values of variables


From   "Peter Dijkstra" <[email protected]>
To   [email protected]
Subject   Re: st: RE: Labeling values of variables
Date   Fri, 15 Feb 2008 13:27:29 +0100

Thanks Nick, it works fine!
I tried to understand what is going on in this program you wrote, but I cannot seem to find out where the variable names and labels are created - I guess I do not know enough of writing programs in Stata. What if I want to create the variable names "demograph_married_male" or label "married, male"?
Cheers, Peter

-------- Original-Nachricht --------
> Datum: Thu, 14 Feb 2008 15:46:57 -0000
> Von: "Nick Cox" <[email protected]>
> An: [email protected]
> Betreff: st: RE: Labeling values of variables

> 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"?
-- 
Psst! Geheimtipp: Online Games kostenlos spielen bei den GMX Free Games! 
http://games.entertainment.web.de/de/entertainment/games/free
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index