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 8042559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:37:24+00:00 2026-06-05T04:37:24+00:00

I am new to Stata and macros. I am trying to loop over several

  • 0

I am new to Stata and macros.

I am trying to loop over several variables to generate estimates from the mlogit command and then save them in datasets. That portion is working well.

The problem I have is a categorical variable that I need to split into dummy variables:

global mypath "/Volumes/NO NAME/Dissertation/Data/AIM 2"
use "$mypath/AIM 2 DATA"
global SES "sesq2 sesq3 sesq4 sesq5"

/*regression*/

foreach xvar in age_median female marital ethnicity literacy $SES poor_health physical_median mental_median facility_fee time_clinic {
    mlogit trauma_main `xvar', b(5) vce(cluster ea_id) rrr
    parmest, saving("$mypath/multi_`xvar'.dta", replace)
}

I thought that by setting SES as a global variable, the loop would treat that as one set of variables, but I was mistaken. The code loops over every variable in $SES so I end up with each dummy variable regressed onto trauma_main separately, which is not what I want.

Is there a way to “tell” Stata to treat the dummy variables as one block? Additionally, I know that I could do i.SES and using that does work fine, but the reference group that is used is not the one that I want. I have googled how to set the reference group for something like i.var, but I am coming up with nothing useful, likely because I am using the wrong search terms.

Thank you in advance for any advice.

Maggie

  • 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-06-05T04:37:26+00:00Added an answer on June 5, 2026 at 4:37 am

    You do not need to split your categorical variable into dummies. You can use the factor variables notation (i.) instead. This is documented in help fvvarlist. With factor variables, a change of the reference category is straightforward.

    Here is an example. The site variable has three categories. By default site = 1 is the reference category for the categorical variable:

    webuse sysdsn1, clear

    foreach v in age male i.site {
    mlogit insure `v’
    }

    With ib you can set the reference category to any desired level. If you want site = 2 as the reference, you can do the following:

    foreach v in age male ib2.site {
    mlogit insure `v’
    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to C and trying to recurse through all directories/files from the current
I'm completely new to stata . I'm trying to merge 3 different datasets which
New to PHP and MySQL, have heard amazing things about this website from Leo
new to c#. I'm trying to make a simple system where I can search
Okay: I'm fairly new to C++ and static languages on a whole. Coming from
When I use the outreg command in stata to export to one file and
How to add new State/Province and City dropdown in Magento 1.6.2? When we choose
I bought a new 320GB SATA hard drive few months ago no recently when
I'm new to Android dev. There's a very pretty state diagram of the MediaPlayer
First let me state that, despite being a fairly new practitioner of TDD, I'm

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.