Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Getting all independent vars from a set of reg equations


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Getting all independent vars from a set of reg equations
Date   Mon, 27 Jun 2011 13:06:51 +0200

On Mon, Jun 27, 2011 at 11:08 AM, Narahari H.S. wrote:
> However, I have a large number of independent variables and their total no. of characters exceeds 244 - thus resulting in a truncation. How do I tackle this?

In the code I sent I deliberately did _not_ say anything like -local x
= ...- but always -local x ...- or -local x : ...-. The 244 character
limit for strings does not bite as long as you do not evaluate your
macros (i.e. as long as you leave the =-sign out) . See among others:

Nicholas J. Cox (2008) "Stata tip 70: Beware the evaluating equal
sign" The Stata Journal, 8(4): 586-587.

> Also, among the independent variables, I have dummy variables for years which are named with a "y" prefix (like y2000, y2005 etc.). Is there any way to drop these variables? (I was hoping for a -drop y*- command similar to -list uniq- but thats not available)

There are many nice tricks for manipulating lists in this way in the
extended macro function, see -help macro- and click on the link for
extended macro functions. On top of that you will want to expand a
variable list and store the expanded list in (another) macro. This you
can do with -unab-. The example below combines these two in order to
exclude such a set of dummy/indicator variables.

*---------------- begin example -----------------------
sysuse auto, clear

// generate dummies
tab rep78, gen(rep)
// exclude reference category
drop rep1

reg price mpg foreign
indeplist
local x = r(X)

reg price mpg rep? foreign
indeplist
local x "`x' `r(X)'"

reg price mpg rep? foreign gear_ratio
indeplist
local x "`x' `r(X)'"

di "`x'"

local x : list uniq x
di "`x'"

// get names of the dummies
unab dummies : rep?
di "`dummies'"

// remove dummies from x
local x : list x - dummies

di "`x'"
*------------------ end example ----------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index