Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating variable to be used in code

    HI,

    this is a very simple question, which I can't find a solution to due to a lack of knowing how to name it.

    I wish to define a variable at the beginning of my dofile, such as x=53 (as well as strings), which I can later use in my code. For example, instead of writing 53 in the option of some package, I'd like to be able to write eg

    Code:
    command1 var3,option1(x)
    so that I can easily vary x in my code. I assume this can be solved through tempvar and local, but I can't figure out how.

    Best,
    Marco

  • #2
    You want to use a local macro. To increase your familiarity with macros, you should review Section 18.3 of the Stata User's Guide PDF included in the Stata installation (since version 11) and accessible from within Stata - for example, through Stata's Help menu.

    Your question is fairly basic, and suggests to me that you have not made thorough use of Stata's documentation. When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. There are a lot of examples to copy and paste into Stata's do-file editor to run yourself, and better yet, to experiment with changing the options to see how the results change.

    The objective in doing the reading was not so much to master Stata as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

    The Stata documentation is really exemplary - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

    Comment

    Working...
    X