Announcement

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

  • Using egen function to create variables

    Clyde Schechter

    I will like to find out how I can use egen to find
    1. how do i create a new variable which is the percentage of 17-20 years in poverty in each district.
    2. how do I create two variable which has min and max percentage of young adults age 17 - 20 at the schools district levels within the state?
    3. how do I create a new dataset which will have a min and max percentage of young adults in poverty at school districts for each state?
    4. how do I generate a new variable, which is the difference between the smallest and the largest percent of children in poverty

    Sample of my data below:
    state postal code State FIPS Code District ID Name Total Population Population 17 -20 Estimated Number of relevant young between ages 17 to 20 years old in poverty who are related to househould
    Al 01 00190 Alabaster Ciety school district 34,015 6,703 860
    Al 01 00020 Albertville city school 21,786 2,659 1,546
    AL 02 00030 Alexander City school 17,073 2,659 832
    AL 02 00060 Andalusia City School 8,854 1,444 386
    AL 03 00090 Andalusia 22,350 3184 1,106
    AL 03 00100 Anthes 22,668 3,340 870
    Thank you







  • #2
    So, there are two things you need to do before you can begin to write code for this.

    You need to bring the data into Stata. If it is in a spreadsheet or .csv file, -import excel- or -import delimited- will be your best approach.

    There are obvious errors in your data. The variable state indifferently as "Al" (lower-case ell) and "AL." You need to consistently refer to the same state with the same abbreviation. In addition, your "state FIPS code" variable takes on three different values for this one state. Again, this variable is not going to be usable with these internal inconsistencies.

    Once you have a Stata data set and the data look reasonable, please post back and show an example of the data using the -dataex- command. If you are running version 15.1 or a fully updated version 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.

    I also recommend that before you proceed with an actual data analysis project, you familiarize yourself with the basic "bread and butter" Stata commands that are used all the time in data management and analysis. The simplest way to do that is to pull down the Help menu in Stata and select PDF Documentation. From there, open and read the User's Guide [U] and Getting Started [GS] sections. You won't remember everything after a single read, but at least you will be exposed to the commands that everybody needs to know. You may find that just from doing that you can answer some of the questions you posed in #1. And if not, you will at least be better positioned to understand code that might be shown to you by others.

    Comment


    • #3
      You surely can start by typing - help egen - in the command window.
      Best regards,

      Marcos

      Comment

      Working...
      X