Statalist


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

Re: st: automatically label interaction terms


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: automatically label interaction terms
Date   Mon, 21 Jul 2008 11:57:00 -0400

Andrea Bennett <[email protected]>:
Sorry... -xi- and -xi3- don't allow you to automatically create nice
labels.  But it's easy to make your own program that does: open xi.ado
in your favorite text editor, make two small changes, and save as a
renamed file elsewhere, e.g.

findfile xi.ado
doedit `r(fn)'

Now change
 label var `svn'`k' "`vn'==`value'"
to
 label var `svn'`k' "`: label (`vn') `value''"
and change
 program define xi
to
 program define xil
and save as xil.ado in `c(sysdir_personal)' then try running

clear all
sysuse auto
la val rep78 rep78
la def rep78 1 ", Worst Repair Record", modify
la def rep78 2 ", Poor Worst Repair Record", modify
la def rep78 3 ", Fair Repair Record", modify
la def rep78 4 ", Good Repair Record", modify
la def rep78 5 ", Best Repair Record", modify
egen ok=group(for rep78), label
xil i.ok

This approach uses the value labels of a categorical var to create
nice labels for dummies downstream.  If all you want to do is label
vars created from the product of two vars, it's as simple as

sysuse auto, clear
g wl=weight*length
la var wl "`: var label weight' * `: var label length' "
d wl

Now that I reread your post, though, after thinking through a
different problem altogether than the one you wanted answered, I
realize you want Stata to look through all var labels to find an
instance of a variable name, and change all those labels at the same
time it renames a var.  So try

prog relab
 version 8.2
 syntax varname, to(string)
 loc f "`varlist'"
 foreach v of varlist _all {
  loc i "`: var label `v''"
  la var `v' "`=subinstr("`i'","`f'","`to'",.)'"
  }
 ren `f' `to'
end

sysuse auto, clear
g wl=weight*length
la var wl "weight * length"
relab weight, to(height)

Which renames and fixes labels simultaneously, but is not too smart
about detecting potential mistakes you might make...

On Mon, Jul 21, 2008 at 11:04 AM, Austin Nichols
<[email protected]> wrote:
> Andrea Bennett <[email protected]> :
>  findit interaction
> finds -xi- but not -xi3- for some reason.  So see also  -findit xi3-
>
> On Mon, Jul 21, 2008 at 10:54 AM, Andrea Bennett <[email protected]> wrote:
>> Dear all,
>>
>> I wonder if anyone knows a user written Stata command which allows one to
>> generate interaction terms, e.g. -female*age- or -female*group1-,
>> -female*group2- and -female*group3-, so that the labels of each variable are
>> used for the interaction terms (e.g. "female * age", "female * social class
>> 3").
>>
>> I just fear that at the end of the day, I will want to rename a few
>> variables. If one could only rename one variable (the non-interacted) and
>> the rest would be automatically generated, that would take away some
>> replacing besides the fact that the do-file won't grow that much...
>>
>> Looking forward to any inputs! Kind regards,
>>
>> Andrea
>
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index