Announcement

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

  • Creating categorical variables with multiple different conditions from continuous variables

    Hi,

    I am trying to create a categorical variable of "activity". I want 0=<150 mins of activity. and 1=>/equal to 150mins of activity.
    I have two continuous variable categories:
    Moderate for which each frequency = 15 mins (e.g. 4 = 60 mins)
    Strenuous for which each frequency = 30 mins (e.g. 4 = 120 mins)

    I want the categorical variable to be able to be = 1 for any combination of the continuous variables that is >/equal to 150 mins or =0 if <150 mins of activity.

    Is anyone able to help by providing some advice as to the type of commands which would be suited to this?

    Thank you
    Ben

  • #2
    Welcome to Statalist.

    Perhaps the following example will show a useful approach.
    Code:
    generate activity = (moderate*15 + strenuous*30) >= 150
    If I've not correctly understood your problem, which seems likely, then take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful to use the dataex command to provide sample data, as described in section 12 of the FAQ.

    The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

    Comment


    • #3
      Hi,

      Thank you, you have understood exactly what I meant. Sorry I am new to stata and trying to get used to how it works.

      The above does exactly what I want except for that it has included missing data as either =0 or =1. Is there a way for it to exclude missing data?

      Thank you for all your help so far.

      Ben

      Comment


      • #4
        The following will produce a missing value rather than a 1 or 0 if either moderate or strenuous is missing.
        Code:
        generate activity = (moderate*15 + strenuous*30) >= 150 if !missing(moderate,strenous)

        Comment

        Working...
        X