# Cannot use "clear all" command in a mod file

**URL:** <https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779>\
**Category:** Installation and Setup\
**Created:** [19 May 2024 20:27 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779 "2024-05-19T20:27:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julie](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/4af34b/32.png) [@Julie](https://forum.dynare.org/u/Julie)\
**Post date:** [19 May 2024 20:27 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779/1 "2024-05-19T20:27:40Z")

</div>

Hi professor,

Could you please let me know why I cannot use the “clear all” command at the top of the dynare file as in Matlab? While “close all” and “clc” work just fine as in Matlab? please find below the screenshot of the error message.

 ![image](https://forum.dynare.org/uploads/default/original/3X/e/5/e5731e8dae29da9d515e596af62050ead64cc8cf.png)

I tried to write a Matlab file with “clear all” and add it to the mod file  
to automate it, without any success.

Is there any alternative to “clear all” used in dynare mod file to clean the workspace?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [20 May 2024 15:59 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779/2 "2024-05-20T15:59:40Z")

</div>

You are supposed to run `clear all` before calling Dynare, not within the mod-file. If you really not to clear the workspace every time you run Dynare, you can write a Matlab script with just the `clear all` and the call to Dynare.

---

<div class="post-metadata">

**Author:** ![Julie](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/4af34b/32.png) [@Julie](https://forum.dynare.org/u/Julie)\
**Post date:** [20 May 2024 16:13 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779/3 "2024-05-20T16:13:51Z")

</div>

Could you explain in more detail by providing a simple example?

thanks!

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [20 May 2024 16:44 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779/4 "2024-05-20T16:44:07Z")

</div>

See `run_example1.m`, which just contains

```auto
clear all
dynare example1.mod

```

[example1.mod](https://forum.dynare.org/uploads/short-url/iN94o1wrfIy0hn3fzFP9lpcfrg3.mod) (1.5 KB)  
[run\_example1.m](https://forum.dynare.org/uploads/short-url/gVOyRpwohb6ycphqrFz0JwSePvW.m) (32 Bytes)

---

<div class="post-metadata">

**Author:** ![Julie](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/4af34b/32.png) [@Julie](https://forum.dynare.org/u/Julie)\
**Post date:** [21 May 2024 09:52 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779/5 "2024-05-21T09:52:36Z")

</div>

Yes, it worked!!

another question is:

[test.mod](https://forum.dynare.org/uploads/short-url/jn3zLwoxyqqFL3Ffo1P7j915aga.mod) (10.1 KB)

could you please let me know what’s wrong the this mod file. The idea is to switch between two regimes: IT targeting and NGDP targeting (lines 140-147)

 ![image](https://forum.dynare.org/uploads/default/original/3X/2/6/26d8535b9bd190699561438b11da0436222bd6b6.png)

and plot bond supply stack\_b ( generated over 500 values of chi) against 9 variables on the SAME figure for comparison.

I proceeded in 2 runs:

For the 1st run, I commented out line 147 while uncommenting line 142 in the model block - choosing IT targeting equation.

And commented out lines 373-385 while uncommenting lines 344-363 for plotting under regime 1 and saved the result.

 ![image](https://forum.dynare.org/uploads/default/original/3X/4/3/4398a0091834308c0df12bf9300ab6c11b3caf21.png)

For the 2nd run, I did the opposite - switching from line 142 to 147 in the model block - choosing NGDP targeting inflation equation

And commented out lines 344-363 while uncommenting lines 373-385 for plotting under regime 2 and added the result generated under regime 2.

However, the lines generated under 2 regimes coincide…

 ![2nd run](https://forum.dynare.org/uploads/default/original/3X/e/8/e893ae0b1a70c9334c8846f455f7ce5fd3ccc3fd.png)

what’s wrong with my code/approach?

Thanks for your help in advance!

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [23 May 2024 12:43 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779/6 "2024-05-23T12:43:19Z")

</div>

Have you checked that the two mod files generate different results for things like IRFs?

---

<div class="post-metadata">

**Author:** ![Julie](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/4af34b/32.png) [@Julie](https://forum.dynare.org/u/Julie)\
**Post date:** [23 May 2024 14:42 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779/7 "2024-05-23T14:42:56Z")

</div>

[quote=“Julie, post:5, topic:25779”]  
n  
I didn’t compute IRFs, but did compare mean and variance of taxes between 2 regimes by using the update code attached here:  
[test\_updated.mod](https://forum.dynare.org/uploads/short-url/gK4ftRBYx1SlIFFY0RrDKYKA2kt.mod) (11.9 KB)

which gave the desirable results as below

 ![tax_comparison](https://forum.dynare.org/uploads/default/original/3X/f/c/fcbbad99a200d3e6032f51c326b27d260bc8be81.jpeg)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [24 May 2024 11:38 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779/8 "2024-05-24T11:38:26Z")

</div>

I tried to clean up your files. Please continue working with them. I introduced a macro switch to switch between cases:  
[steady\_helper.m](https://forum.dynare.org/uploads/short-url/d7qZ3f1aXOpUYU7DBsAQsjVqmbq.m) (217 Bytes)  
[test\_updated.mod](https://forum.dynare.org/uploads/short-url/dSOs8lK5lDJXv9M04XkT0bMXNtl.mod) (9.9 KB)  
[run\_test\_updated.m](https://forum.dynare.org/uploads/short-url/91zfJzZtZFrm5ynorXLAFbSs9hi.m) (73 Bytes)

---

<div class="post-metadata">

**Author:** ![Julie](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/4af34b/32.png) [@Julie](https://forum.dynare.org/u/Julie)\
**Post date:** [24 May 2024 13:24 UTC](https://forum.dynare.org/t/cannot-use-clear-all-command-in-a-mod-file/25779/9 "2024-05-24T13:24:25Z")

</div>

I tried your updated code which still gave the same results as before…

two lines coincided for the 3\*3 plot, while for comparison of taxes, they worked fine.

 ![Screenshot 2024-05-24 142229](https://forum.dynare.org/uploads/default/original/3X/c/b/cb68c3cadce640fdc4c9ad53593873a6b30460e8.png)  
 ![Screenshot 2024-05-24 142245](https://forum.dynare.org/uploads/default/original/3X/b/e/bef5bcf6471a70bdd1acb120647ad9244ff84416.png)
