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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: SV: egen and variabel list


From   Tomas Lind <Tomas.Lind@ki.se>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] För Tomas Lind
Skickat: den 2 juli 2012 15:35
Till: statalist@hsphsun2.harvard.edu
Ä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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index