Announcement

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

  • twoway bar command

    Hi everyone. I have the 2019 LFS data and I am trying to produce a bar chart that describes the percentage of individuals who are immigrants by province. I want to use the two-way bar command. Can anyone help me with the syntax?

    The data for immigration includes three cases:
    1 Immigrant, landed 10 or less years earlier
    2 Immigrant, landed more than 10 years earlier
    3 Non-immigrant

    The Provinces are :
    10 Newfoundland
    11 Prince Edward Island
    12 Nova Scotia
    13 New Brunswick
    24 Quebec
    35 Ontario
    46 Manitoba
    47 Saskatchewan
    48 Alberta
    59 British Columbia

    I only want to include four provinces (Newfoundland, New Brunswick, Nova scotia, and Prince Edward Island).

    I tried twoway bar immig prov if prov=="Newfoundland, New Brunswick, Nova Scotia, Prince Edward Island" but it didn't work

    I would appreciate it if anyone can tell me what syntax I should use?
    Last edited by Kiana Delavarkasmaei; 24 May 2021, 13:48.

  • #2
    Copy and paste the result of

    Code:
    dataex immig prov

    Comment


    • #3
      Code:
      twoway bar immig prov if prov=="Newfoundland, New Brunswick, Nova Scotia, Prince Edward Island"
      would be legal if and only if prov is a string variable and will be wrong for your purposes even then as it tests for equality with a string that won't occur in your data.

      Andrew Musau gives excellent advice, which is just that given in our FAQ Advice, to give a data example. WIth some wild guesses, I imagine that you need something like this


      Code:
      egen pc_immig = mean(100 * inlist(immig, 1, 2)), by(prov) 
      
      egen tag = tag(prov) 
      
      twoway bar pc_immig prov if tag & inlist(prov, 10, 11, 12, 13) , xla(10/13, valuelabel) ytitle(% of immigrants)
      Here note inlist() as what you are reaching for, some syntax to indicate that any value from a specified list will do.

      Comment


      • #4
        Thank you very much for your help, Nick. I appreciate it
        Attached Files
        Last edited by Kiana Delavarkasmaei; 25 May 2021, 13:25.

        Comment


        • #5
          Code:
          twoway bar pc_immig prov if tag & inlist(prov, 10, 11, 12, 13) || scatter pc_immig prov if tag & inlist(prov, 10, 11, 12, 13), mlabel(pc_immig) msym(none) mlabpos(12) ||, xla(10/13, valuelabel) ytitle(% of immigrants)
          Last edited by Ali Atia; 25 May 2021, 12:56.

          Comment


          • #6
            The graph in #4 would be much better horizontal and without axis ticks.

            Comment


            • #7
              How can I add the sample weight variable (fweight) to the command below?

              egen pc_immig = mean(100 * inlist(immig, 1, 2)), by(prov)

              egen tag = tag(prov)

              twoway bar pc_immig prov if tag & inlist(prov, 10, 11, 12, 13) || scatter pc_immig prov if tag & inlist(prov, 10, 11, 12, 13), mlabel(pc_immig) msym(none) mlabpos(12) ||, xla(10/13, valuelabel) ytitle(% of immigrants)
              Last edited by Kiana Delavarkasmaei; 01 Jun 2021, 13:56.

              Comment

              Working...
              X