Announcement

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

  • variable labels

    sex age response freq
    0 0 0 26
    0 0 1 12
    0 0 2 7
    0 1 0 9
    0 1 1 21
    0 1 2 15
    0 2 0 5
    0 2 1 14
    0 2 2 41
    1 0 0 40
    1 0 1 17
    1 0 2 8
    1 1 0 17
    1 1 1 15
    1 1 2 12
    1 2 0 8
    1 2 1 15
    1 2 2 18
    I supposed to import above data into Stata and save it as a dta file. Next instructions are to label variables and the variable responses for variables Sex, Age and response; produce three 1-ways tables of these categorical variables which display the frequency of subjects in each category. Please suggest if my approach and output is right. here it is:

    First, I set my working directory
    cd "C:\Users\HP\Desktop"
    C:\Users\HP\Desktop
    (a) Import the data into Stata
    import delimited car_preferences.csv, delimiters (",") clear
    (4 vars, 18 obs)

    Checking to see if I got all the variables and obs
    describe

    Contains data
    obs: 18
    vars: 4
    size: 72
    -------------------------------------------------------------------------------------------
    storage display value
    variable name type format label variable label
    -------------------------------------------------------------------------------------------
    sex byte %8.0g
    age byte %8.0g
    response byte %8.0g
    freq byte %8.0g
    -------------------------------------------------------------------------------------------
    Sorted by:
    Note: Dataset has changed since last saved.

    Saving a Stata version of the file
    save car_prefernces.dta

    file car_prefernces.dta saved


    (b) label the variable and variable responses
    label variable sex "sex"
    label variable age "age group"
    label variable response "importance of air conditioning and power steering in cars"

    I haven't labelled frequency.

    Checking to see my labelled variables.

    describe
    Contains data from car_prefernces.dta
    obs: 18
    vars: 4 15 Aug 2019 05:00
    size: 72
    -------------------------------------------------------------------------------------------
    variable storage display value
    name type format label variable label
    -------------------------------------------------------------------------------------------
    sex byte %8.0g sex
    age byte %8.0g age group
    response byte %8.0g importance of air conditioning and power steering in cars
    freq byte %8.0g
    -------------------------------------------------------------------------------------------

    creating value labels for sex, age and response variable. Also, displaying 1-way frequency table for each categorical variable
    label define sex 0 "women" 1 "men"
    label values sex sex
    numlabel, add
    tabulate sex

    sex | Freq. Percent Cum.
    ------------+-----------------------------------
    0. women | 9 50.00 50.00
    1. men | 9 50.00 100.00
    ------------+-----------------------------------
    Total | 18 100.00


    label define age 0 "18 - 23" 1 "24 - 40" 2 "41 - 60"
    label values age age
    numlabel, add
    tabulate age
    age group | Freq. Percent Cum.
    ------------+-----------------------------------
    0. 18 - 23 | 6 33.33 33.33
    1. 24 - 40 | 6 33.33 66.67
    2. 41 - 60 | 6 33.33 100.00
    ------------+-----------------------------------
    Total | 18 100.00

    label define response 0 "no/little" 1 "important" 2 "very important"
    label values response response
    numlabel, add
    tabulate response

    importance of air |
    conditioning and |
    power steering in |
    cars | Freq. Percent Cum.
    ------------------+-----------------------------------
    0. no/little | 6 33.33 33.33
    1. important | 6 33.33 66.67
    2. very important | 6 33.33 100.00
    ------------------+-----------------------------------
    Total | 18 100.00

    Checking to see if I got all labelled variables and obs
    Describe
    Contains data from car_prefernces.dta
    obs: 18
    vars: 4 15 Aug 2019 05:00
    size: 72


    -------------------------------------------------------------------------------------------
    variable storage display value
    name type format label variable label
    -------------------------------------------------------------------------------------------
    sex byte %8.0g sex sex
    age byte %10.0g age age group
    response byte %17.0g response importance of air conditioning and power steering in cars
    freq byte %8.0g
    -------------------------------------------------------------------------------------------



    And next part is to estimate the mean age of subjects in the datesets using the midpoints of the age. Dispaly this with the number of subjects in the dataset (N). Also display the mean age & the number of subjects(N) for men and women separately. Can you please suggest commands for this part.

    Thanks

  • #2
    Testing a post
    Dar

    Comment

    Working...
    X