I am trying to loop drawnorm over mutiple STATA datasets, however I want drawnorm to use the existing variable names from the original dataset and I don't want to define them manually in my script each time.
My problem is that I can't seem to find a varlist macro that drawnorm will accept for the variable names, I have tried to use the "ds" function to send information to a matrix - which hasn't worked. And various other bits and pieces, but still can't get it to work. As you can see from "X_names", writing out the variable names manually works.
Any help would be greatly appreciated!
Josh
Code:
clear all
sysuse auto
drop make
save auto_test.dta, replace
local X_var `r(varlist)'
//local X_names price mpg rep78 headroom trunk weight length turn displacement gear_ratio foreign
corr `X_var'
matrix m_corr= r(C)
quietly tabstat _all, stat(sd) save
matrix m_sd= r(StatTotal)'
quietly tabstat _all, stat(mean)save
matrix m_mean= r(StatTotal)'
drawnorm `X_var', n(10000) means(m_mean) sds(m_sd) corr(m_corr) cstorage(full)
0 Response to Using macros with Drawnorm to "clone" multiple datasets
Post a Comment