<>
Michael suggested a suggestion using local macros. Another way to skin
this cat would be via Mata (borrowing Michael's setup code)
clear
mata:mata clear
set obs 100
// six observations per case with an income and month number for
each obs
forvalues i = 1/6 {
gen ing_`i' = 100000 * runiform()
gen mes_`i' = round((runiform()*(6-1))+1)
}
su ing*
forv i=1/6 {
local ingl "`ingl' ing_`i'"
local mesl "`mesl' mes_`i'"
}
mata
// fill in with deflators for each calendar month
def = ( 1, 1.1, 1.2, 1.3, 1.4, 1.3, 1.2, 1.1, 1, 1.1, 1.2, 1.3)
st_view(Y=., ., st_local("ingl"))
st_view(M=., ., st_local("mesl"))
for(j=1;j<=rows(Y);j++) {
for(i=1;i<7;i++) {
Y[j,i] = Y[j,i] :/ def[M[j,i]]
}
}
end
su ing*
Kit Baum | Boston College Economics & DIW Berlin | http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming
| http://www.stata-press.com/books/isp.html
An Introduction to Modern Econometrics Using Stata | http://www.stata-press.com/books/imeus.html
On Aug 12, 2009, at 02:33 , Dan wrote:
I have data in monthly expenditures in variables ing_1 through
ing_6, and survey months in variables mes_1 through mes_6 (these
vary from respondent to respondent). I wish to adjust the monthly
expenditures for inflation, and I have deflation factors in
variables def_1 through def_12.
I am pretty accomplished in SAS, but only a novice in Stata. In SAS
I would say:
array def {12} def_1 - def_12;
array ing {6} ing_1 - ing_6;
array mes {6} mes_1 - mes_6;
do t=1 to 6;
month=mes{t};
ing{t}=ing{t}/def{month};
end;
*
* 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/