Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4603188
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:06:28+00:00 2026-05-22T00:06:28+00:00

I recently got into Stata coming from a procedural/OO/functional background, and am having trouble

  • 0

I recently got into Stata coming from a procedural/OO/functional background, and am having trouble understanding the basic elements of the language.

For example, I discovered that there is a syntax command which “allows programs to interpret the arguments the user types according to a grammar, such as standard Stata syntax”. I infer this is the reason why some command require a list of variables given as arguments to be separated by whitespaces while others require a comma-separated list. But the idea of a program defining its own syntax instead of the (parameter) syntax being enforced seems plain weird.

Another quite interesting construct is the syntax for macro definition and expansion (`macro') and the apparent absence of local variables as known in other languages.

Is there something like a “Stata for Java developers” document explaining the basic concepts of the language to people with my background?

PS: Apologies if this question seems unclear. Unfortunately, I can’t formulate more concrete/clear questions at this point 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:06:29+00:00Added an answer on May 22, 2026 at 12:06 am

    I’m not exactly sure what you are looking for… but here’s a few related points. Stata is kind of like writing a Unix shell script or a Windows batch file. Each line executes a command, and the first word is the command name. By convention, most commands have the following structure:

    command [varlist] [=exp] [if expression] [in range] [weight] [using filename] [, options]
    

    Brackets [.] means it’s optional (or unavailable, depending on the command). Some commands can be prefixed (such as by:, xi:, or svy:) The syntax of commands by Stata Corp and experienced users are pretty consistent. But, because Stata users also write commands, you occasionally see things that are wacky.

    When Stata users write commands, they are saved in .ado files (not .do) and are defined using the program command. (See help program and the “Ado files” section of the manual.) Writing a command is akin to writing a function in other languages (e.g., MatLab)

    The syntax command is used to help you write your own command. When you execute a command, everything following the command’s name (command above) is passed to the program in the local macro `0'. The syntax command parses this local macro, so that you can reference `varlist' or `if' and so on. In theory, you could parse `0' yourself, but the syntax command makes it much easier for you and your users (as long as you are following the conventional syntax). I put an example at the bottom.

    I don’t know exactly what you mean by “apparent absence of local variables as known in other languages.” Macros store a single string or a single number in memory. Here’s a comment I wrote about Stata’s local/global macros. They are indeed a unique feature of Stata’s programming language. As their names imply, “local” macros are only available within a specify program (command) or .do file while “global” macros are available throughout a Stata session.

    I found that, once I got used to macros in Stata, I started to miss them in other languages. They are pretty handy. In addition to (local/global) macros and the main data set, you can also store “things” in memory with the scalar and matrix commands (and one or two other obscure things).

    I hope that helps. Here’s a list resources that might help.

    Example:

    program define myprogram
        syntax varlist [if], [hello(string) yes]
        macro list _0 _varlist _if _hello _yes 
        summarize `varlist' `if'
        display "Here's the string in my hello option: `hello'"
        if !missing("`yes'") di "Yes is on"
        else                 di "Yes is off"
    end 
    
    sysuse auto.dta    
    myprogram rep78 headroom if price > 5000 , hello("world") yes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently got into Java. I have a background in dynamic languages and I'm
I just recently got into using vim, and am having great fun adding load
I got into a mini-argument with my boss recently regarding project failure. After three
I recently got a notification from a McAfee service (what used to be called
I recently got into Silverlight development. So far I've managed to create a single
I am programming in PHP mysql. I have recently got into OOP programming. So
Recently I got into a discussion with my Team lead about using temp variables
Just recently got into experimenting with NLog, and it occurs to me that I
Alright well I recently got into normalizing my database for this little side project
I got into django recently and start playing around with the tutorials & documentation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.