I have a Stata file file1.dta
and one of the variables is income
. I need to calculate average_income
, assign it to a local macro, and store in a different Stata file, New.dta
.
I have tried the following in a do
file:
#delimit;
clear;
set mem 700m;
use file1.dta;
local average_income = mean income;
use New.dta;
gen avincome = average_income;
However, it does not work.
One way to do this would be the following:
#delimit;
clear;
set mem 700m;
use file1.dta;
quietly: summarize income;
local average_income = r(mean);
use New.dta;
gen avincome = `average_income';