Announcement

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

  • Append data bases with same variables name but diffrents type!

    Hello everyone,

    I am trying to append these four other databases with mhws_rd1.dta. There are many similar variables with different types. What code can I use so that, when appending the other datasets, the variables adopt the type of the first one? Actually the final data gets missing points for the variables.

    Thank you


    use "C:\Users\Utilisateur\OneDrive - Université Laval\Article 1 thesis\Data Havard\mhws_rd1.dta", clear


    append using "C:\Users\Utilisateur\OneDrive - Université Laval\Article 1 thesis\Data Havard\mhws_rd2.dta", force


    append using "C:\Users\Utilisateur\OneDrive - Université Laval\Article 1 thesis\Data Havard\mhws_rd3.dta", force

    append using "C:\Users\Utilisateur\OneDrive - Université Laval\Article 1 thesis\Data Havard\mhws_rd4.dta", force

    append using "C:\Users\Utilisateur\OneDrive - Université Laval\Article 1 thesis\Data Havard\mhws_rd5.dta", force

    append using "C:\Users\Utilisateur\OneDrive - Université Laval\Article 1 thesis\Data Havard\mhws_rd6.dta", force

    Here is the code that I tried, uncessful!

    clear *

    capture program drop one_file
    program define one_file
    * Définir le répertoire et le nom du fichier
    local dirname "C:\Users\Utilisateur\OneDrive - Université Laval\Article 1 thesis\Data Havard"
    local filename = filename[1]

    * Charger le premier fichier
    use `dirname'\`filename', clear

    * Ajouter les autres fichiers
    append using "`dirname'\mhws_rd2.dta", force
    append using "`dirname'\mhws_rd3.dta", force
    append using "`dirname'\mhws_rd4.dta", force
    append using "`dirname'\mhws_rd5.dta", force
    append using "`dirname'\mhws_rd6.dta", force

    exit
    end

    * Lister les fichiers .dta dans le répertoire
    filelist, pattern(*mhws_rd1.dta)

    * Exécuter le programme one_file pour charger et ajouter les fichiers
    runby one_file, by(dirname filename) verbose


  • #2
    This is a duplicate of the post here. OP: Please post at only one place.

    Please continue the discussion on the other thread, not here.

    Comment

    Working...
    X