How to rewrite this Stata code in R?

后端 未结 4 643
挽巷
挽巷 2021-01-02 07:34

One of the things Stata does well is the way it constructs new variables (see example below). How to do this in R?

foreach i in A B C D {  
    forval n=1990         


        
4条回答
  •  旧巷少年郎
    2021-01-02 08:25

    Assuming you have population data in vector pop1989 and data for trend in trend.

    require(stringr)# because str_c has better default for sep parameter
    dta <- kronecker(pop1989,cumprod(1+trend))
    names(dta) <- kronecker(str_c("pop",LETTERS[1:4]),1990:2000,str_c)
    

提交回复
热议问题