[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Dan Waldo <dwaldo@aresearch.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: using vector notation to simplify coding |

Date |
Wed, 12 Aug 2009 11:04:34 -0400 |

Dan Kit Baum wrote:

<>Michael suggested a suggestion using local macros. Another way to skinthis 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 foreach obsforvalues 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.htmlAn Introduction to Stata Programming| http://www.stata-press.com/books/isp.htmlAn Introduction to Modern Econometrics Using Stata |http://www.stata-press.com/books/imeus.htmlOn 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 fromrespondent to respondent). I wish to adjust the monthly expendituresfor inflation, and I have deflation factors in variables def_1through def_12.I am pretty accomplished in SAS, but only a novice in Stata. In SAS Iwould 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/

-- Daniel Waldo Actuarial Research Corporation 5950 Symphony Woods Road, Suite 510 Columbia, Maryland 21044 410.740.9194 ext 19 * * 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/

**References**:**Re: st: using vector notation to simplify coding***From:*Kit Baum <baum@bc.edu>

- Prev by Date:
**st: Computing medcouple** - Next by Date:
**re: st: using vector notation to simplify coding** - Previous by thread:
**Re: st: using vector notation to simplify coding** - Next by thread:
**re: st: using vector notation to simplify coding** - Index(es):

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