Announcement

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

  • Creating a dummy variable for each observation separately

    Hello,

    I have a nummeric variable which is represented in % and I need to recode this variable. To be specific, I need to have for each observation that has a value >0 a different natural number. The goal is to create a fixed effect dummy for a regression analysis. So, for instance:

    Observation 1: value 5 --> obtains value 1
    Observation 23: value 3 --> obtains value 2
    Observation 58: value 9 --> obtains value 3
    ...etc

    Is there a command that can do that automatically?

    Thanks in advance!


  • #2
    Sebastian:
    do you mean something along the following lines?
    Code:
    . set obs 3
    number of observations (_N) was 0, now 3
    
    . g A=runiform()/100
    
    . egen flag=group(A) if A>0
    
    . list
    
         +-----------------+
         |        A   flag |
         |-----------------|
      1. | .0034887      3 |
      2. | .0026689      2 |
      3. | .0013665      1 |
         +-----------------+
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hello,

      thanks for your answer. I tricked around after a bit of waiting and I found a solution: I made an "inverse"-string command and then used the encode command to get the values I wanted. Sorry for bothering!

      Have a nice day!

      Comment


      • #4
        Sebastian:
        thanks for sharing your solution.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment

        Working...
        X