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]

st: SV: egen and variabel list


From   Tomas Lind <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: SV: egen and variabel list
Date   Mon, 2 Jul 2012 14:13:53 +0000

Dear All,

I found the solution! The problem lies in the first line where I define the local var. There should be no = sign

This work!

local  var    O3_0_7

and this work also

local var = "O3_0_7"

/Tomas



-----Ursprungligt meddelande-----
Från: [email protected] [mailto:[email protected]] För Tomas Lind
Skickat: den 2 juli 2012 15:35
Till: [email protected]
Ämne: st: egen and variabel list

Dear Statalist,

I´m trying to calculate the maximum value from 17 variables with these variable names (where "O3" is ozone")
O3_0_7 
O3_1_8  
O3_2_9 
 O3_3_10.  
. . . . . 
O3_16_23  

As I may later on want to expand the range of the ozone variables it would be nice if I could use a local macro to generate the variable names. It seems to work fine (the display statement works)  but none of the two -egen rowmax- works. You see the error messages after the //.

I´m using Stata 11 under Windows. Has anyone a solution to this?

/Tomas


local  var  = O3_0_7
forval i= 0(1)16     {
local  j = `i'+7
local  var    "`var'  O3_`i'_`j'"  
  } 
di "`var'" //   O3_0_7   O3_1_8   O3_2_9   O3_3_10  . . . . .  O3_16_23  (Total 17 variables)
 

egen O3max  = rowmax(`var') 	 // invalid name
egen O3max  = rowmax("`var'") 	 // factor variables and time-series operators not allowed


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

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