Announcement

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

  • Generating categorical variable

    In my Stata data set, the "alternative" variable consists of 4 modes including pier, private, beach and charter.

    I want to generate new variable y as follows:

    We collapse the model to three alternatives and order the alternatives, with y = 0 if fishing from a pier or beach, y = 1 if fishing from a private boat and y = 2 if fishing from a charter.

    The descriptions of variables in the dataset is as follows:


    Click image for larger version

Name:	Screen Shot 2022-05-03 at 8.33.20 PM.png
Views:	1
Size:	68.5 KB
ID:	1662838


    Note: I don't understand from the dataset. And I get error related to type of the variable while generating variable I download the dataset from the website https://www.stata-press.com/data/musr/musr.zip The data name is mus15data

    How can I generate the variable y?
    Last edited by Sean Bilic; 03 May 2022, 12:38.

  • #2
    Hi, try this:
    Code:
    gen y=.
    replace y=0 if dbeach==1 | dpier==1
    replace y=1 if dprivate==1
    replace y=2 if dcharter==1

    Comment


    • #3
      Cross-posted at https://stackoverflow.com/questions/...rical-variable

      Please note our policy about cross-posting, explained in the FAQ Advice you are asked to read before posting, which is that you are asked to tell us about it. https://www.statalist.org/forums/help#crossposting

      Comment

      Working...
      X