Hi everyone,
I am trying to find a more concise way to create 19 variables based on the following code:
And so on up to #19. I tried the following foreach loop, but got an error message stating "invalid syntax":
The data looks something like this:
Could someone please recommend a correct for loop, or another way to create these new variables?
Thank you!
I am trying to find a more concise way to create 19 variables based on the following code:
Code:
egen total_saksinnhold_1 = total(saksinnhold_1), by(id_lnr) egen total_saksinnhold_2 = total(saksinnhold_2), by(id_lnr) egen total_saksinnhold_3 = total(saksinnhold_3), by(id_lnr)
Code:
foreach v of varlist saksinnhold* { egen total_`v’= total(`v’), by(id_lnr) }
Code:
input str10(id_lnr) byte(saksinnhold_1 saksinnhold_2 saksinnhold_3 saksinnhold_4 saksinnhold_5) "idlnr1" 0 1 0 0 0 "idlnr1" 0 0 0 0 0 "idlnr2" 1 0 0 0 0 "idlnr2" 0 1 0 0 0 "idlnr2" 0 0 0 0 0
Thank you!
Comment