Question

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.

Was it helpful?

Solution

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';

OTHER TIPS

This overlaps with your other post, namely How to retrieve data from multiple Stata files?. You don't say why you think

use file1.dta;
local average_income = mean income; 

will work, but the second line is just fantasy syntax. There are various ways to calculate the mean of a variable, the most common being to use summarize and pick up the mean from r(mean).

You should probably delete this question: it serves no long-term purpose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top