Announcement

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

  • Xi Regression

    As someone who just started using Stata, I am throwing a trivial question. I am using Xi regression to create dummies of variable with many observations like say country and year (with i.country and i.year). In the output I get these variable with _I prefix and ascending numbered suffix like _Icountry_1 rather than say Australia. How do I change this to get original country names as in data rather "_Icountry_1" format?

  • #2
    unless you are using a very old version of Stata, see
    Code:
    h fvvarlist

    Comment


    • #3
      Originally posted by Rich Goldstein View Post
      unless you are using a very old version of Stata, see
      Code:
      h fvvarlist
      I still don't get it, say I am using "xi: reg var1 var2 i.country i.year" where to use fvvarlist? I am using latest Stata

      Comment


      • #4
        Originally posted by lab rath View Post

        I still don't get it, say I am using "xi: reg var1 var2 i.country i.year" where to use fvvarlist? I am using latest Stata
        If you are using the latest Stata, then you are learning from, or copying, very outdated code. The -xi- prefix was a way for Stata to automatically generate indicator variables (and their interactions) as a syntactical convenience so that you, the programmer, wouldn't need to worry about it. In modern Stata, since at least version 12 (or thereabouts), factor variable notation is supported by nearly all Stata commands where it makes sense to use them. This is the help document that Rich has pointed you to. The page at -help fvvarlist- explains how factor variable syntax works.

        You don't "use" fvvarlist. Instead, the -i.- prefix you have used in your example is an example of how to use factor variables. Simply drop the -xi:- prefix and forget that it even exists, and run your regression as:

        Code:
        reg var1 var i.country i.year

        Comment


        • #5
          Also by way of introduction to Stata, I strongly suggest that you spend some time to read through the getting started manul. -help getting started-. Start at Chapter 1, and work your way through. The time spent learning is well worth your efforts and will payback dividends in your future use of Stata as the documentation is very clearly written.

          Comment


          • #6
            Originally posted by Leonardo Guizzetti View Post

            If you are using the latest Stata, then you are learning from, or copying, very outdated code. The -xi- prefix was a way for Stata to automatically generate indicator variables (and their interactions) as a syntactical convenience so that you, the programmer, wouldn't need to worry about it. In modern Stata, since at least version 12 (or thereabouts), factor variable notation is supported by nearly all Stata commands where it makes sense to use them. This is the help document that Rich has pointed you to. The page at -help fvvarlist- explains how factor variable syntax works.

            You don't "use" fvvarlist. Instead, the -i.- prefix you have used in your example is an example of how to use factor variables. Simply drop the -xi:- prefix and forget that it even exists, and run your regression as:

            Code:
            reg var1 var i.country i.year
            Thank you so much, this is indeed helpful and I would definitely go through the suggested manual, right now just recreating some previous work with those "older" codes. So now I tried dropping xi and it gave error of string variables like country (or country code). If I convert them it would again be numeric and not the actual name that I want in the output. So instead of Australia it will be give me say 2 but I want Australia etc. My apologies for such trivial questions without going through the manual. Really appreciate your help.

            Comment


            • #7
              So you need to use -encode- to create a value-labeled numeric variable from your string variable. (If you follow Leonardo Guizzetti's excellent advice in #5 you will learn about value-labeled numeric variables.) Meanwhile, so you can make progress on your immediate situation:
              Code:
              encode country, gen(ctry)
              reg var1 var i.ctry i.year

              Comment


              • #8
                Originally posted by Clyde Schechter View Post
                So you need to use -encode- to create a value-labeled numeric variable from your string variable. (If you follow Leonardo Guizzetti's excellent advice in #5 you will learn about value-labeled numeric variables.) Meanwhile, so you can make progress on your immediate situation:
                Code:
                encode country, gen(ctry)
                reg var1 var i.ctry i.year
                Awesome, it worked well. Thank you all of you. Has been really great learning on this forum and this post alone so far.

                Comment

                Working...
                X