Announcement

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

  • From Alphabet letter to number

    Dear all,
    I have this problem that I hope you may help me.
    I have a list of companies name and a list of ticker symbols for each company. For instance, the company Apple has the ticker AAPL.
    I want to regress the first letter of the company name on the first letter of ticker symbol.
    I have a panel data.
    This is what I've done:
    Code:
    gen firstic= substr(tic,1,1)
    gen firstconm= substr(conm,1,1)
    encode firstic, gen(ticletter)
    encode firstconm, gen(conmletter)
    Now, for the purpose of the regression I need to convert the letters in numbers. For example "A" is "1", "B" is "2" and so forth.
    Do you have any suggestions?
    Moreover, there are some companies which the name starts from a number, how can I solve it? In this case I should assign them a different value. For instnace if a company first letter is A, the value assigned to that letter could be 1. But what about a first company letter that is 1? I hope you see my point
    Finally, since it is a panel data, and I have 16.032 unique firms (with a unique identifier, namely the GVKEY) how can I perform a regression focusing only one time for each firm?
    To be more clear, I cannot do
    Code:
    reg firsttickerletter firstcompanyletter if year==2019
    Because I'm missing companies that are in the database in 2015 and not in 2019 for instance. I should do a regression for only 16032 observations
    Thank you in advance for your time and help

  • #2
    You didn't get a quick answer. You will increase your chances of useful answer by providing Stata code in code delimiters (which you do), readable Stata output, and sample data using dataex.

    Your explanation is not very clear or at least I'm having trouble understanding it. You can assign numbers to letters by doing a loop over the letters and having a counter something like:

    local num 1
    g wnum=.
    foreach var in A B C {

    replace wnum=`num' if substr(tic,1,1)==`var'
    }

    Not having data, I haven't checked this for errors.

    What it means to perform regression focusing only one time for each firm I don't really understand.

    You certainly can loop over gvkeys or tickers and run separate regressions for each firm.

    I wonder if it wouldn't be better to do a two way table instead of regression.

    Comment


    • #3
      Hello, I need your help guys, the code is below. I only want to report the coefficient of “drop1”

      foreach var of varlist SR_health1 SR_health2 health_trans {

      probit `var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1 [pw=WEIGHT] if age_group==1 & year<2014, robust
      eststo
      probit`var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1[pw=WEIGHT] if age_group==2 & year<2014, robust
      eststo
      probit `var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1 [pw=WEIGHT] if age_group==3 & year<2014, robust
      eststo
      probit `var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1 [pw=WEIGHT] if age_group==4 & year<2014, robust
      eststo
      probit `var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1 [pw=WEIGHT] if age_group==5 & year<2014, robust
      eststo
      ***post 2014
      probit `var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1 [pw=WEIGHT] if age_group==1 & year>=2014, robust
      eststo
      probit `var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1 [pw=WEIGHT] if age_group==2 & year>=2014, robust
      eststo
      probit `var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1 [pw=WEIGHT] if age_group==3 & year>=2014, robust
      eststo
      probit `var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1 [pw=WEIGHT] if age_group==4 & year>=2014, robust
      eststo
      probit`var' drop1 i.year SEX MAR1 HISPANIC i.RACE i.fam_size1 college i.REGION1 i.POVCAT_Y1 i.inc_group1 employed1 small_firm1 self_emp1 full_time1 HEALTH1 SAQ_HEALTH1 risky1 health_risky1 ins_risky1 exchange1 Public_ins1 HELD1 [pw=WEIGHT] if age_group==5 & year>=2014, robust
      eststo

      }

      Comment

      Working...
      X