Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: Creating interaction and square variables


From   "Mike Kim" <kalisperos@gmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Creating interaction and square variables
Date   Thu, 30 Aug 2012 17:39:30 -0500

Hi all,

I would like to create interaction and square variables. Let say, I have
three variables x1, x2, x3.

I used to the following code to create interactions and square of x1, x2,
x3.

forv i=1/3 {
  forv j=1/3 {
  gen x`i'x`j'=x`i'*x`j'    //  if `i'<=`j'   : This still creates variables
with missing values.
  }
}

Since x1*x2 = x2*x1, for example, I tried to drop those same variables using
the following code, but got error message: "invalid syntax, r(198)". 

forv i=1/3 {
 forv j=1/3 {
 drop x`i'x`j' if  `i'<`j'
 }
}

Can you please let me know what is wrong in the code? Thank you for your
help in advance.

Mike.

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