- Minitab's Macro Library
- Macros Dennis Roberts Developed
- Macros Donated by Others
- Multivarite macros from Eryl Bassett

If you would like to contribute a macro, and/or know of a link to macros that might be helpful to add to this list ... send me a note at ... Dennis Roberts

Macros can be very useful when working in Minitab and, they can serve many functions. In general, the main reason why people would create a maco would be to eliminate the need for having to REenter commands over and over again for some commonly used routine. Here are a few general pointers to keep in mind about macros ... at least the old time exec files.

- You can use a text editor to create the macro file and then save, and run in Minitab when needed.
- Make sure that you don't save the files in your normal word processing package using the normal file extensions like .doc for word or .wpd for word perfect. These are not necessarily true text files. It would be better to use something like notepad to create and save these files ... using the .mtb extension.
- Don't forget the HISTORY window in the process of making a macro file. If you run through a set of commands in the session window that will do what you want, the actual commands that were used will appear in the history window ... and you could cut and paste these into notepad and give a name for your macro file.
- % files in Minitab (like %describe) are simply macro files that have been created to add certain capabilities to Minitab without having to alter the overall program code.

What if you wanted to set up a standard scenario where you generated some data, and then found the standard error of the mean for the set of data, and then did this over and over and wanted to see the complete set of standard errors of the mean (for example). In this case, we will randomly generate a sample of n=25 from a normal distribution where the mean = 100 and the standard deviation = 15. Then, we find the standard deviation of the sample, and divide by the square root of the sample size ... to get the standard error of the mean. Then, we do this over and over and finally look at the set of standard errors that has been generated. Here is a macro for doing that.

rand 25 c1; norm 100 15. let k2=stdev(c1) let k3=k2/sqrt(n(c1)) let c2(k1)=k3 let k1=k1+1 end

The first 2 lines generate 25 values at random from a normal distribution with mean = 100 and standard deviation = 15 into c1. Next, the standard deviation of the sample is stored in k1. Then the standard deviation (k2) is divided by the square root of the sample size .. and that calculation is put in k3. k3 is our standard error of the mean. Now, the line ... let c2(k1)=k3 will take the result .... that is k3 or the standard error and put it in the FIRST row (k1) of c2. Then, the line ... let k1=k1+1 is there to bump up the ROW location in c2 to the next row. So, when we save this file as something like ... stanerr.mtb ... and execute it while in Minitab ... we could do something like the following:

MTB> let k1=1

MTB> exec 'a:\stanerr' 100

Minitab will then go find the file on your floppy and run it 100 times ... and then put all of those standard error values, all 100 of them, in c2. So, when you look at the data in c2, it will be the results from the running of this macro 100 separate times. The important part of this macro is the bumping up bit ... the let c2(k1)=k3 ... and the let k1=k1+1 ... these two allow you (just before you run the macro and have put MTB> let k1=1) to start with the first row on c1 with the first result ... and then bump the row to 2 ... so that the next run of the macro will put the second result in the SECOND row of c2, etc.

This bump up feature is very helpful in macros where you want to do multiple calculations of some routine, and want to store each of the results so as to be able to summarize these later. For example, you could simulate a sampling distribution of means by using the above to store the means of samples ... and then make a dotplot of the column where you stored all the mean values ... and see what the simulated sampling distribution looks like.

Here is how the macro output looks when I ran it once. You must put at the MTB> prompt PRIOR to running the macro, let k1=1.

MTB > let k1=1 MTB > exec 'd:\macros\bump' 5 Executing from file: d:\macros\bump.MTB MTB > prin c2 Data Display C2 3.54442 2.83121 3.50812 2.99020 2.63451

In this case, I ran the macro 5 times so, the output 5 values are the 5 standard errors of the means. If I had put 100, it would have done this 100 times. Now, I had named my macro bump.mtb .... and had stored it on drive d in a subdirectory called macros. You would fill in the location where you had stored your file and you will use the name that you have given.

rand 100 c1-c36; norm 100 16. rmean c1-c36, c37 name c37='sampmean' rstdev c1-c36, c38 name c38='sampsd' let c39=c38/6 name c39='stanerr' let c40=c37-(2*c39) let c41=c37+(2*c39) let c42=(c40 lt 100) and (c41 gt 100) let k1=sum(c42) let k2=k1/100 prin k2 end

The first 2 lines simply generate 36 columns of n=100 each, data from a normal distribution with mean = 100 and standard deviation = 16. I have found it is easier to use a ROW as a sample ... not a column. rmean takes the mean for each row and puts it in c37 ... same thing for the standard deviation of the row (ie, each sample) and puts it in c38. c39 is the standard error of the mean. c40 and c41 are the lower and upper boundary points of the 95% confidence interval ... using 2 standard error units as the distance to go. let c42 uses LET to evaluate the logical expression of seeing whether EACH of the confidence intervals contains the paramter value of 100 ... or does not. The let expression essentially says: if the value of c40 is less than 100 AND the value in c41 is greater than 100 ... put a value of 1 in c42. IF both of those conditions are met ... then the interval captures the parameter. Since we have built the intervals going about 2 units of error on either side of the sample mean, our expectation IF WE WANT TO CALL THESE 95% CONFIDENCE INTERVALS, is that about 95% of the 100 intervals should contain 100. Of course, you could easily modify this macro to make your sample size different, or you could randomly generate data from other distributions. That is a nice thing about a macro, YOU can make it do whatever YOU want it to do!

Here is an example of running this macro once.

MTB > exec 'd:\macros\distsamp' Executing from file: d:\macros\distsamp.MTB Data Display K2 0.940000

The run of the macro in this case found that 94% of the confidence intervals captured the true population mean.

Note: This macro will let you enter a mean and standard deviation Note: from a normal distribution, and then request that the score Note: value for some specific percentile rank be found. Note: Note: What is the mean you want to use for the normal distribution? noecho set 'terminal' c50; nobs=1. copy c50 k1 echo Note: What is the standard deviation of the normal distribution? noecho set 'terminal' c51; nobs=1. copy c51 k2 echo Note: What is the percentile rank you want to work with? [NOTE: make Note: sure you enter this as a decimal ... ie, 75th pr should be Note: entered as .75 ... 45th = .45, etc. } noecho set 'terminal' c52; nobs=1. copy c52 k3 echo Note: The baseline value for you percentile rank is ... noecho invcdf k3; norm k1 k2. end

Now, there is a tad more explanation needed for this one. First, when I put Note: at the side ... this is just my way of starting the message that will appear on the screen when the macro is run. So, Note: will be where I want the macro to DISPLAY a message to the user. ECHO and NOECHO are used so that you can SEE on the screen what follows or NOT see on the screen what follows ... when the macro is run. In the above macro, note that when you see ECHO, what follows is information that I want printed out on the screen when the user runs the macro. Now, look at this little part of the macro..

set 'terminal' c50; nobs=1. copy c50 k1

After I have displayed on the screen the question to the user, "What is the mean ... ?", I want the user to input the value of the mean. The macro will pause here to let the user type that in ... say ... 100. Then, when the ENTER or RETURN key is hit, the macro will take that value of 100 ... store it over in the first row of c50 .. then copy it to a constant location k1. Thus, k1 will equal the mean that the user inputted. Since I used noecho just above this, the user will NOT see that operation on the screen ... it will be transparent. Then you see that I put ECHO again, just before I want the second question listed out on the screen ..."What is the standard ... ?".

invcdf k3; norm k1 k2.

Finally, after I have stored the standard deviation in k2 and the percentile rank in k3, I do the final calculation using the INVCDF command in Minintab ... to find the baseline value, and that is what is printed out. Of course, the user could run this macro again and again ... changing the values for the means, and/or standard deviations, and/or percentile ranks.

Here is the output from one run of the macro..

MTB > exec 'd:\macros\pr' Executing from file: d:\macros\pr.MTB This macro will let you enter a mean and standard deviation from a normal distribution, and then request that the score value for some specific percentile rank be found. What is the mean you want to use for the normal distribution? DATA> 100 MTB > Note: What is the standard deviation of the normal distribution? DATA> 16 MTB > Note: What is the percentile rank you want to work with? [NOTE: make MTB > Note: sure you enter this as a decimal ... ie, 75th pr should be MTB > Note: entered as .75 ... 45th = .45, etc. } DATA> .35 MTB > Note: The baseline value for you percentile rank is ... Inverse Cumulative Distribution Function Normal with mean = 100.000 and standard deviation = 16.0000 P( X <= x) x 0.3500 93.8349

What you see is what was displayed on the screen as the macro ran and the values that I input. The baseline value for the 35th percentile rank in this case is about 93.8.

Top of page ... Top of Page ... Return to MTB Resources Page ... MTB Resources Page