Announcement

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

  • Creating tertiles from subset of data

    Hello,

    I am looking for guidance on the following issue:

    I have a quantitative variable that I would like to define all values as the following
    <=150 = 0
    151 to maximum = tertile 1, tertile 2, and tertile 3

    How do I create tertiles for values from 151 to maximum without including values <=150?

    Any help would be greatly appreciated.
    Best,
    Lesley

  • #2
    Code:
    xtile wanted = my_variable if my_variable > 150, nq(3)
    replace wanted = 0 if my_variable <= 150
    In the future, when asking for help with code, please use the -dataex- command and show example data. Although sometimes, as here, it is possible to give an answer that has a reasonable probability of being correct, this is usually not the case. Moreover, such answers are necessarily based on experience-based guesses or intuitions about the nature of your data. When those guesses are wrong, both you and the person trying to help you have wasted their time as you end up with useless code. To avoid this, a -dataex- based example provides all of the information needed to develop and test a solution.

    If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment

    Working...
    X