Announcement

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

  • Country Fixed Effects

    Hmmm...an easy question

    How could I generate country fixed effects, based on a string variable (loc) that contains country names?

    Tried run

    xtreg .... i.loc ...

    didn't work. Destring...generate () force also didn't work.

    Thank you!

  • #2
    Edward:
    -i.loc- with a string variable won't work.
    Then you should convert it in numeric format, as in the following toy-example:
    Code:
    . set obs 3
    number of observations (_N) was 0, now 3
    
    . g loc="Rome" in 1
    (2 missing values generated)
    
    . replace loc="Paris" in 2
    variable loc was str4 now str5
    (1 real change made)
    
    . replace loc="London" in 3
    variable loc was str5 now str6
    (1 real change made)
    
    . g count_city=_n
    
    . label define count_city 1 "Rome" 2 "Paris" 3 "London"
    
    . label val count_city count_city
    
    . list loc count_city
    
         +-------------------+
         |    loc   count_~y |
         |-------------------|
      1. |   Rome       Rome |
      2. |  Paris      Paris |
      3. | London     London |
         +-------------------+
      
    In you future post, please use -dataex- to provide an excerpt/example of your data, so that interested listers can give you more helpful replies. Thanks.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Alternatively

      Code:
      egen countrynum=group(country)
      will assign a number for each country. Then i.countrynum works for the dummies. Alternatively, you can use it in the xtset.

      Comment


      • #4
        Thanks both!! It worked! Have a wonderful weekend!

        Comment

        Working...
        X