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, 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 <>
To   "" <>
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"


-----Ursprungligt meddelande-----
Från: [] För Tomas Lind
Skickat: den 2 juli 2012 15:35
Ä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")
. . . . . 

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?


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:

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index