Announcement

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

  • combining multiple strings from 2 string variables into a number in one numeric variable

    Hi,

    I have two string variables with non-formatted responses from a survey. These refer to the level of education on each parent. I would like to combine those two string variables into a numeric variable, where various strpos are combined into one number.

    For example, looking at the data below (it's in Portuguese, sorry) I'd like to generate a new variable stating whether both parents had attended higher education or not. So I need to know:
    1) How can I first convert the multiple strpos of each variable that might refer to HE into one number?
    2) How could I then combine the same number of both parents into the new variable to represent both parents having attended HE?

    Click image for larger version

Name:	Screenshot 2022-01-19 104910.png
Views:	1
Size:	70.3 KB
ID:	1645741



  • #2
    Cristina:
    since you neither provide and example/except of your data via -dataex- (BTW: please note tha FAQ discourage posting attachments for sound reasons) nor detail when from what level of education a "higher education" is actually pursued according to Portuguese education system, guess-work and a toy-examples are the best resources:
    Code:
    . set obs 2
    Number of observations (_N) was 0, now 2.
    
    . g Father_edu="Superior"
    
    . replace Father_edu="Primary" in 2
    (1 real change made)
    
    . g Mother_edu="Superior"
    
    . g Check_edu=0 if Father_edu!=Mother_edu
    (1 missing value generated)
    
    . replace Check_edu=1 if Father_edu==Mother_edu
    (1 real change made)
    
    . label define Check_edu 0 "Education levels differ" 1 "Both mother and father pursued superior education level"
    
    . label val Check_edu Check_edu
    
    . list
    
         +-------------------------------------------------------------------------------+
         | Father~u   Mother~u                                                 Check_edu |
         |-------------------------------------------------------------------------------|
      1. | Superior   Superior   Both mother and father pursued superior education level |
      2. |  Primary   Superior                                   Education levels differ |
         +-------------------------------------------------------------------------------+
    
    .
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Dear Carlo,

      Thank you for the support and explanation despite the limited detail on my part. This has helped indeed.

      Kind regards,
      Cristina

      Comment

      Working...
      X