Statalist The Stata Listserver


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

Re: st: Truncation of long variable names with xi


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: Truncation of long variable names with xi
Date   Thu, 31 Aug 2006 16:07:13 +0900

Melissa A. Clark wrote:

I would like to loop through several categorical variables, run
regressions of an outcome on these variables using the "xi" command,
and then manipulate the regression results for each dummy variable
created by xi.  However, with long variable names, xi truncates the
names of the newly created dummy variables, so I am unable to refer to
variable "_Ilongvariablename" after running the regression.  Does
anyone know of a solution (other than giving my variables shorter
names)?

Here is an example of my code:

foreach var of varlist a b c longvariablename d e f g {;
xi: svy: outcome i.`var' ;
                postfile `results' beta se using `signif';
 foreach binary of varlist _I`var'_* {;
  post `results' (_b[`binary']) (_se[`binary']) ;
  };
 postclose `results';
};

--------------------------------------------------------------------------------

For simple cases, i.e., if you're not generating interaction terms, it looks
like -xi- takes the first nine characters of the variable name.  So, you can
create a local macro containing the first nine characters of the variable
name using -substr("`var'", 1, 9)-, and then use that as your identifier.

The technique is illustrated below using the same variable names that you 
use in your example.

Joseph Coveney

clear
set more off
set seed `=date("2006-08-31", "ymd")'
set obs 10
foreach var of newlist a b c longvariablename d e f g {
    generate byte `var' = floor(ceil(2 +10 * uniform()) * uniform())
}
*
* Begin here
*
foreach var of varlist a b c longvariablename d e f g {
    xi i.`var'
    local stub = substr("`var'", 1, 9)
    foreach binary of varlist _I`stub'_* {
        display in smcl as input "`binary'"
    }
}
exit


*
*   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