Hi, thanks in advance for you help. I 've got problem with macro. I don't how to automate same transformations.I want to have 50 bases with 1000 cases and only 2 variables: DEFINE macro1 (arg1=!TOKENS(1)) INPUT PROGRAM. loop #i=1 to 1000. compute id=#i. compute z1=RV.UNIFORM(1, 100). end case. end loop. end file. END INPUT PROGRAM. EXECUTE. dataset name !arg1. !enddefine. macro1 base2 ..... macro1 base50 |
I can't solve your Macro/naming problem. But creating 50 separate datasets with
50 separate names leaves you with the further problem of dealing with those
50 names one at a time when it comes to analyses.
The usual procedure for 50 randomizations is to create a counter from 1 to 50
and process the one file using Split File.
--
Rich Ulrich
From: SPSSX(r) Discussion <[hidden email]> on behalf of 88Videoclips . <[hidden email]>
Sent: Sunday, April 2, 2017 2:23:06 PM To: [hidden email] Subject: Problem with macro Hi, thanks in advance for you help.
I 've got problem with macro. I don't how to automate same transformations.I want to have 50 bases with 1000 cases and only 2 variables: DEFINE macro1 (arg1=!TOKENS(1)) INPUT PROGRAM. loop #i=1 to 1000. compute id=#i. compute z1=RV.UNIFORM(1, 100). end case. end loop. end file. END INPUT PROGRAM. EXECUTE. dataset name !arg1. !enddefine. macro1 base2 ..... macro1 base50 |
As Rich said, you will wind up with 50 different open datasets, which are not saved. Is that really what you want? Easy to do, though, with a small amount of Python code, which is simpler than wading through macro.. begin program. import spss for i in range(3): spss.Submit(r"""INPUT PROGRAM. loop #i=1 to 1000. compute id=#i. compute z1=RV.UNIFORM(1, 100). end case. end loop. end file. END INPUT PROGRAM. dataset name base%s.""" %i) end program. On Mon, Apr 3, 2017 at 10:19 AM, Rich Ulrich <[hidden email]> wrote:
-- |
In reply to this post by 88videos
Concerning draws values from a (continuous) uniform distribution.
This means that all values have the same chance of occurring. An example are throws with a balanced die: values 1 through 6 all have the same chance of (1/6) of occurring. This can be simulated by TRUNC(RV.UNIFORM(1,7)) . The fractional values are discretized here by truncating them.
-- Rich Ulrich
|
Administrator
|
In reply to this post by 88videos
As others have stated. I doubt that you will want to have 50 datasets. Maybe lookup SPLIT FILE.
What is the intention of this exercise? -- Maybe try the following approach: DEFINE !MakeData (NRows !TOKENS(1) / NSamples !TOKENS(1)) MATRIX. LOOP ID=1 TO NSamples. SAVE ({MAKE(!NRows,1,ID),UNIFORM(!NRows,1)}) / OUTFILE * / VARIABLES ID Uniform01 . END LOOP. END MATRIX. !ENDDEFINE. DATASET NAME simulated. SPLIT FILE BY ID . DESCRIPTIVES Uniform01 .
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Rich Ulrich
First I want to thank all of you. In example I tried to show something. @Rich Ulrich @David Marso "What is the intension of this exercise?" I want to learn how to avoid writing 50 times execution of some macro e.g. macro1 base1, macro1 base2 .. I do this, when in argumentI I have numbers, but have problem with string argument. Easy example with number agument. I want to build 5 AR models: ARIMA (1, 0, 0) ARIMA (2, 0, 0) ARIMA (3, 0, 0) ARIMA (4, 0, 0) ARIMA (5, 0, 0) *1) to generate data for example input program. loop #i=1 to 250. compute id=#i. end case. end loop. end file. end input program. execute. compute z1=RV.UNIFORM(0, 1). execute. *2) writing a macro *2.1) macro without loop inside Define macro2 (arg1=!TOKENS(1)) use thru 240. PREDICT THRU 250. TSMODEL /MODELSUMMARY PRINT=[MODELFIT] /MODELSTATISTICS DISPLAY=YES MODELFIT=[ SRSQUARE] /SERIESPLOT OBSERVED FORECAST /OUTPUTFILTER DISPLAY=ALLMODELS /AUXILIARY CILEVEL=95 MAXACFLAGS=24 /MISSING USERMISSING=EXCLUDE /MODEL DEPENDENT=z1 PREFIX='Model' /ARIMA AR=[!arg1] DIFF=0 MA=[0] ARSEASONAL=[0] DIFFSEASONAL=0 MASEASONAL=[0] TRANSFORM=NONE CONSTANT=YES /AUTOOUTLIER DETECT=OFF. !enddefine. *2.2) macro with loop inside Define macro3 (arg1=!TOKENS(1)) !DO !k=1 !TO !arg1. use thru 240. PREDICT THRU 250. TSMODEL /MODELSUMMARY PRINT=[MODELFIT] /MODELSTATISTICS DISPLAY=YES MODELFIT=[ SRSQUARE] /SERIESPLOT OBSERVED FORECAST /OUTPUTFILTER DISPLAY=ALLMODELS /AUXILIARY CILEVEL=95 MAXACFLAGS=24 /MISSING USERMISSING=EXCLUDE /MODEL DEPENDENT=z1 PREFIX='Model' /ARIMA AR=[!k] DIFF=0 MA=[0] ARSEASONAL=[0] DIFFSEASONAL=0 MASEASONAL=[0] TRANSFORM=NONE CONSTANT=YES /AUTOOUTLIER DETECT=OFF. !DOEND !enddefine. *3) execution of macro *3.1.) macro without loop inside macro2 arg1=1 macro2 arg1=2 macro2 arg1=3 macro2 arg1=4 macro2 arg1=5 *3.2.) macro with loop inside macro3 arg1=5 To sum up. In second solution 1 line, in first 5 lines. I am not sure, but something tells me that similar automation is possible in my 1 example. ??? David, I have to admit that i don' t understand all elements of your syntax commands. "Save ({make" is new for me. Is your syntax is all I need to execute? When I copy/paste/execute it I got error. Maybe I should have made changes in your commands? But without understanding this part save/make i don't know how... Other questions 1) Why you use space instead of "=" to define arguments? That new for me too. 2) In your command I can't see line with execution , "!makeData ....". Why? Thanks for answears. @Jon Peck Thanks, but I try to learn how to solve some problems without programming tricks :) 2017-04-03 19:28 GMT+02:00 Rich Ulrich <[hidden email]>:
|
re: " @Rich Ulrich
I know that ruounding is necessary." Rounding is only half the problem, which truncating makes more evident:
Taking Uniform from 1 to 100 gives a range of 99, with 1/99 being the probability for most integers. Trunc( ) would mean that you would never see 100; Round( ) would mean that you would see 1 and 100 with only a 50% chance of 1/99 for each, a fault that would be harder to notice.
-- Rich Ulrich |
@ Rich Ulrich Good point.2017-04-08 19:08 GMT+02:00 Rich Ulrich <[hidden email]>:
|
Free forum by Nabble | Edit this page |